Hi Guys,
Finally decided to sign up because I couldn't find a topic on this. Everyone has been most helpful in the past!
I have a table that stores 'news items'. This contains an auto-increment column for creating unique id's for each item.
Problem is, whenever I load edit and submit this information via an 'update' sql statement (see below), a new record is created and the original is left in tact, so Two news items now appear. Is it purely that you can not 'update' records that use the auto-increment?
"UPDATE news SET title='$title', body='$body' WHERE id='$id'"
Thanks in advance!
J
MySql UPDATE creates new record
Moderator: General Moderators
-
jamespenney
- Forum Newbie
- Posts: 2
- Joined: Wed May 27, 2009 11:11 am
- jayshields
- DevNet Resident
- Posts: 1912
- Joined: Mon Aug 22, 2005 12:11 pm
- Location: Leeds/Manchester, England
Re: MySql UPDATE creates new record
You can update any record, whether it usese auto-increment or not. Maybe the ID you are using in your WHERE clause doesn't exist. Get your script to output the whole executed query and also show us both the old record you're trying to update and the new record.jamespenney wrote:Is it purely that you can not 'update' records that use the auto-increment?
-
jamespenney
- Forum Newbie
- Posts: 2
- Joined: Wed May 27, 2009 11:11 am
Re: MySql UPDATE creates new record
You genius. It's been a long day!!!
The $id was not carried correctly up to the point where it needed to be used as a reference for this statement!!!
Thanks for bringing it to my attention, I was going mad!!!

ETA: Apologies to all for being so hasty with my posting!!
The $id was not carried correctly up to the point where it needed to be used as a reference for this statement!!!
Thanks for bringing it to my attention, I was going mad!!!
ETA: Apologies to all for being so hasty with my posting!!