Newbie PHP/Mysql question

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
TomEd
Forum Newbie
Posts: 2
Joined: Fri Jan 10, 2003 11:23 am
Location: South Florida

Newbie PHP/Mysql question

Post 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
Rob the R
Forum Contributor
Posts: 128
Joined: Wed Nov 06, 2002 2:25 pm
Location: Houston

Post 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' ) ");
TomEd
Forum Newbie
Posts: 2
Joined: Fri Jan 10, 2003 11:23 am
Location: South Florida

Post 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
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Post 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
Post Reply