Page 1 of 1

getting duplicate record inserted using mysql PHP

Posted: Wed Apr 18, 2007 10:46 am
by panusrini_1984
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] 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]


Hi All,

I am getting duplicate record inserted in the mysql database using PHP.
could [s]u[/s] [color=green]you[/color] please help,

Code: Select all

$sql=INSERT INTO mydetails (uid, user_email, status, date_posted, expirationdate, state, city, locality, price, availability, payment_terms)VALUES( '1', 'hgsd@yahoo.com', 'pending,'2007-04-18' ,'18-05-2007', 'Ca', 'sdfasd','sdfa','123','yes','bycard');

$query_result = mysql_query($sql);

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] 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: Wed Apr 18, 2007 10:47 am
by RobertGonzalez
Show us some more code. Showing us the query only doesn't allow us to gauge the problem at all.

Posted: Thu Apr 19, 2007 1:25 am
by panusrini_1984
NO other code is there simple taking the values from the form page and inserteng top db , getting duplicate values inserted.

Posted: Thu Apr 19, 2007 2:06 am
by aaronhall
Start by enclosing the entire query in double quotes (as you should when declaring any string). There is nothing in this code that would cause your query to execute twice... it's likely that it's something before or after. Post it.

Posted: Thu Apr 19, 2007 11:28 am
by eeve
Check if your browser is double submitting the page. Javascript can cause this for example.

Posted: Thu Apr 19, 2007 7:15 pm
by bdlang
Obviously the PHP code you've posted is incorrect, as aaronhall alluded to.

I did notice something odd with your query, you have as first on your list a column named `uid` and are inserting a string '1' into that column. What type of column is `uid`? I would assume based on my experience that it's supposed to be an auto_increment INT type column, but if you haven't defined it that way you could most certainly get duplicate records. You should definitely not be attempting to insert a value to that column, especially not a numeric value in quotes.

Please post your table definition.