SQL Query

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
hewstone
Forum Newbie
Posts: 14
Joined: Fri Nov 14, 2008 10:57 am

SQL Query

Post by hewstone »

Hey guys,

I have the code below which inputs data in a database, however instead of inputted the values i want, it inputs the string: Is there someting wrong with $RowName?

$ColName = "Col1,Col2,Col3";
$RowName = "'$line[0]','$line[1]','$line[2]'";

$data = file_get_contents($table);
$rows = explode("\n", $data);
foreach($rows as $row){
$line = explode(',', $row);
$SQLCODE = "INSERT INTO TempData($ColName) VALUES($RowName)";
$rS = $db_conn->execute($SQLCODE);

}
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: SQL Query

Post by califdon »

echo out $SQLCODE and see what you get. Also, add
or die(mysql(error)); to your execute command.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: SQL Query

Post by requinix »

You can't "prepare" a variable for use later. When you define it, that's when it gets a value - PHP won't go back and fill in the blanks.

Talking about $RowName here. It gets the value "'','',''" (since $line is undefined) and you never change that.
Post Reply