Page 1 of 1

Newbie PHP/Mysql question

Posted: Fri Jan 10, 2003 11:23 am
by TomEd
I'm trying to use the following script to update a test database and it errors out. I can't seem to figure it out.
<?
$db = mysql_connect("localhost","root");

mysql_select_db (recipes);

$result = mysql_query ("INSERT INTO (name,ingredients,directions,yield,category)
VALUES ('$name' , '$ingredients' , '$directions' , '$yield' , '$category' ) ");
if(!$result)
{
echo "<b>Something not added:</b> <br>", mysql_error();
exit;
}
if($result)
{
mysql_close($db);
print "Something added sucessfully!";
}
?>
Here's the error...
Something not added:
You have an error in your SQL syntax near '(name,ingredients,directions,yield,category) VALUES ('' , '' ,' at line 1

Thank you

Posted: Fri Jan 10, 2003 11:54 am
by Rob the R
You're missing a table name in your insert statement:

Code: Select all

$result = mysql_query ("INSERT INTO tablename(name,ingredients,directions,yield,category) 
VALUES ('$name' , '$ingredients' , '$directions' , '$yield' , '$category' ) ");

Posted: Fri Jan 10, 2003 12:07 pm
by TomEd
DUH :oops: I feel stoopit!

Thank you very much.
I looked at that line a million times and still couldn't see that. I feel kinda foolish, but after all I can claim "newbie" as my defense.(I hope)

Thanks again
Tom

Posted: Fri Jan 10, 2003 12:44 pm
by BDKR
TomEd wrote:DUH :oops: I feel stoopit!

Thank you very much.
I looked at that line a million times and still couldn't see that. I feel kinda foolish, but after all I can claim "newbie" as my defense.(I hope)

Thanks again
Tom
I seem to remember that I was a newbie once too. Don't sweat it.

One hint though. Give us the error messages as it will help us figure out what's going on.

Cheers,
BDKR