MySql UPDATE creates new record

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
jamespenney
Forum Newbie
Posts: 2
Joined: Wed May 27, 2009 11:11 am

MySql UPDATE creates new record

Post by jamespenney »

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
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: MySql UPDATE creates new record

Post by jayshields »

jamespenney wrote:Is it purely that you can not 'update' records that use the auto-increment?
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
Forum Newbie
Posts: 2
Joined: Wed May 27, 2009 11:11 am

Re: MySql UPDATE creates new record

Post by jamespenney »

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!!! :banghead:
:D

ETA: Apologies to all for being so hasty with my posting!!
Post Reply