three column record in one row why ?(CSV)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
prashantAG
Forum Newbie
Posts: 7
Joined: Wed Apr 30, 2008 1:31 am

three column record in one row why ?(CSV)

Post 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());

}
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

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

Post by Kieran Huggins »

it's handy to debug SQL queries like this:

Code: Select all

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