Page 1 of 1

three column record in one row why ?(CSV)

Posted: Tue May 06, 2008 8:16 am
by prashantAG
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());

}

Re: three column record in one row why ?(CSV)

Posted: Tue May 06, 2008 10:29 am
by Kieran Huggins
it's handy to debug SQL queries like this:

Code: Select all

$result = MySQL_query("INSERT.....") or die(MySQL_error())