Can anyone see what is wrong with this code, its designed to read a text file and add each part to a database
playerlist.txtCode:Notice: Undefined offset: 1 in /home/n00bless/public_html/status/test/insert.php on line 16
Notice: Undefined offset: 2 in /home/n00bless/public_html/status/test/insert.php on line 16
Notice: Undefined offset: 3 in /home/n00bless/public_html/status/test/insert.php on line 16
Notice: Undefined offset: 4 in /home/n00bless/public_html/status/test/insert.php on line 16
Notice: Undefined offset: 5 in /home/n00bless/public_html/status/test/insert.php on line 16
Code:player GDI 100 5 2 67
otherplayer Nod 300 6 0 98
PHP Code:
<?php
include ("config.php");
$oldErrorLevel = error_reporting (E_ALL);
if ( !$playerlistTXT = file_get_contents ( "playerlist.txt" ) )
$updateError = true;
else
{
mysql_query ( "TRUNCATE TABLE status" );
$playersArray = explode ( "\n", $playerlistTXT );
for ( $pos = 0; $pos < sizeof ( $playersArray ); $pos++ )
{
$playersArray[$pos] = explode ( "\t", $playersArray[$pos] );
if ( !mysql_query ( "INSERT INTO status ( name, team, score, kills, deaths, ping ) VALUES ( " . trim ( $playersArray[$pos][0] ) . ", '" . str_replace ( "'", "\'", trim ( $playersArray[$pos][1] ) ) . "', " . trim ( $playersArray[$pos][2] ) . ", " . trim ( $playersArray[$pos][3] ) . ", " . trim ( $playersArray[$pos][4] ) . ", " . trim ( $playersArray[$pos][5] ) . ")" ) )
$criticalError = "<b>An error occured while updating the database!</b><br><i>" . mysql_error() . "</i>";
}
error_reporting ($oldErrorLevel);
}
?>