2

I have a myIsam table people as follow:

[id][name][cat] with values: 12,"John Doe", "worker"

id is unique and name is fulltext.

I put some values inside by a remote file call. Then I change manually cat value to another different value:

[id][name][cat] with values: 12,"John Doe", "player"

When I update values from a remote file again to insert into table, I don't want the column 'cat' get old remote values from file in case row have same id. I just want to keep the manually entered value. But still retrieving the old value!

I am trying with this code and it's doesn't work.

INSERT INTO people (id,name,cat) VALUES (12,'John Doe','worker') ON DUPLICATE KEY UPDATE name = '$name',cat = VALUES(cat);
Jongware
  • 22,200
  • 8
  • 54
  • 100
Angel C.
  • 21
  • 3
  • 1
    If you do not want a value updated, don't do it in the update part, so just remove them from the update... – Naruto Oct 27 '15 at 12:10
  • 1
    Your question is not clear enough. Your SQL does not look correct for what your explination appears to be doing. All rows in the database must have a unique key. You only insert when no row exists with that key. If key alerady exists, you use update. What you seem to be trying is an incorrect 'upsert' type operation. Think you need to go back to basics with your SQL – Tim X Oct 27 '15 at 12:13
  • Thanks @Naruto for your answer. The problem is i removed from update but still appears as updated old value. – Angel C. Oct 27 '15 at 12:49
  • Solved. Was a temporary and crazy failure in mysql server. – Angel C. Oct 27 '15 at 13:13
  • I really hope for your sake that `$name` is [properly escaped](http://bobby-tables.com/php). – tadman Nov 02 '15 at 19:27

0 Answers0