three column record in one row why ?(CSV)
Posted: Tue May 06, 2008 8:16 am
i have three columns in csv i unable to insert in three row in mysql
this code insert all three column record in one row any know this problem help me.
$fcontents = file('C:\Documents and Settings\winfo2\Desktop\user.csv');
for($i=1; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$row = explode("|", $line);
print_r($row[0] );
print_r($row[1] );
print_r($row[2] );
if (!$row[0]) {$row[0] = "0"; }
if (!$row[1]) {$row[1] = "0"; }
if (!$row[2]) {$row[2] = "0"; }
$insertSQL = sprintf("INSERT INTO csv (firstname, username, emaila) VALUES ('%s','%s','%s')",$row[0], $row[1], $row[2]);
$db = mysql_connect("localhost","root","");
mysql_select_db("Azad");
$Result1 = mysql_query($insertSQL) or die(mysql_error());
}
this code insert all three column record in one row any know this problem help me.
$fcontents = file('C:\Documents and Settings\winfo2\Desktop\user.csv');
for($i=1; $i<sizeof($fcontents); $i++) {
$line = trim($fcontents[$i]);
$row = explode("|", $line);
print_r($row[0] );
print_r($row[1] );
print_r($row[2] );
if (!$row[0]) {$row[0] = "0"; }
if (!$row[1]) {$row[1] = "0"; }
if (!$row[2]) {$row[2] = "0"; }
$insertSQL = sprintf("INSERT INTO csv (firstname, username, emaila) VALUES ('%s','%s','%s')",$row[0], $row[1], $row[2]);
$db = mysql_connect("localhost","root","");
mysql_select_db("Azad");
$Result1 = mysql_query($insertSQL) or die(mysql_error());
}