[thelist] MySQL insert fails

NanHarbisonSmith at aol.com NanHarbisonSmith at aol.com
Sun Jul 7 19:16:00 CDT 2002


--
[ Picked text/plain from multipart/alternative ]
Hey Joel,
I always separate the querystring from the result. It is easier to find
mistakes that way, and it makes your code reusable by changing fewer things.
Here is an insert statement that I just copied and pasted from a webpage of
mine:

$Query = "Insert into $TableName values ('0', '$date', '$announce')";
Print ("the query is: <BR>$Query<p>\n");
$Result = mysql_db_query($DBName, $Query, $Link);

try what I have done here, print the query, and make sure it looks correct.
It is a good way to do error checking. You need SINGLE quotes on all values
whether they are hard coded or variables. I have never done what you are
doing, listing the values into specific fields of the db.When I am not
filling all of the fields, I put single quotes around a blank for the one I
am skipping, so I never list all of the fields. And what is the NULL for the
id? If you are autoincrementing the id, you need to put a zero there, the way
I have in my query.
HTH,
Nan




In a message dated 7/7/2002 7:56:21 PM Eastern Daylight Time,
joel at spinhead.com writes:


>
> I can't figure out why this fails:
>
> $result = mysql_query('INSERT INTO music (id, title, artist, album, genre,
> year, rating) VALUES (NULL, \"$title\", \"$artist\", \"$album\",
> \"$genre\",
> $year, $rating)',$db);
>
> I've tried it with single quotes around the statement with escaped double
> quotes around the variables, with no quotes around the variables, etc etc.
>
> Am I even on the right track?
>
> I've been connecting to the db okay, so I don't suspect a
> connection/permissions problem. When I echo the variables, they all have
> values that make sense.
>
> joel


Nan Harbison Smith
481 Elm Street
Concord, MA 01742
978-369-1224
978-369-1681

Deja Moo -- the feeling that you've heard this bull before





More information about the thelist mailing list