Bug when inserting sql row

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
slpshtmike
Forum Newbie
Posts: 4
Joined: Sun Apr 09, 2006 11:09 am

Bug when inserting sql row

Post 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]
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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.
User avatar
ambivalent
Forum Contributor
Posts: 173
Joined: Thu Apr 14, 2005 8:58 pm
Location: Toronto, ON

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

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