getting duplicate record inserted using mysql PHP

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
panusrini_1984
Forum Newbie
Posts: 2
Joined: Wed Apr 18, 2007 10:26 am

getting duplicate record inserted using mysql PHP

Post 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]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Show us some more code. Showing us the query only doesn't allow us to gauge the problem at all.
panusrini_1984
Forum Newbie
Posts: 2
Joined: Wed Apr 18, 2007 10:26 am

Post by panusrini_1984 »

NO other code is there simple taking the values from the form page and inserteng top db , getting duplicate values inserted.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post 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.
eeve
Forum Newbie
Posts: 8
Joined: Thu Jun 09, 2005 3:01 pm

Post by eeve »

Check if your browser is double submitting the page. Javascript can cause this for example.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

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