Page 1 of 1

Bug when inserting sql row

Posted: Sun Apr 09, 2006 11:12 am
by slpshtmike
Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Code: Select all

$dbh = mysql_connect ("localhost", "teamae_mike", "pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db("teamae_negdb");
mysql_query("INSERT INTO `news` (`user`, `cont`, `date`, `title`) VALUES ('$user', '$cont', '$date', '$title')") or die(mysql_error());
for some reason, my script inserts two rows when i run it. ( the second row is full of blank values ).

Has anyone ever encountered an error like this before? I have looked at my code over and over and I cant figure out why its doing that.


Jcart | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sun Apr 09, 2006 11:45 am
by ambivalent

Code: Select all

mysql_query("INSERT INTO `news` (`user`, `cont`, `date`, `title`) VALUES ('$user', '$cont', '$date', '$title')") or die(mysql_error());
Remove the backticks from news, user, etc.

Posted: Sun Apr 09, 2006 12:24 pm
by John Cartwright
ambivalent wrote:

Code: Select all

mysql_query("INSERT INTO `news` (`user`, `cont`, `date`, `title`) VALUES ('$user', '$cont', '$date', '$title')") or die(mysql_error());
Remove the backticks from news, user, etc.
It's actually recommended you always use backticks.


slpshtmike: can you post the full code? It sounds like this snipplet is executed twice.

Posted: Sun Apr 09, 2006 12:47 pm
by ambivalent
Jcart wrote: It's actually recommended you always use backticks.
Indeed, I didn't know that. I've not seen an example of this before.

Posted: Sun Apr 09, 2006 2:08 pm
by timvw
ambivalent wrote:
Jcart wrote: It's actually recommended you always use backticks.
Indeed, I didn't know that. I've not seen an example of this before.
Have a look at sql generated statements by phpmyadmin.. Now, if you need real motivations for this you can always search in the database forum because they've been mentionned a couple of times (+ real examples).