0
$query = "UPDATE TABLE1 
  SET (row1 = '$val1' WHERE row5 = '$someid' AND active = 'yes')
    , (row1 = '$val2' WHERE row5 = '$someid' AND active = 'yes')
    , (row1 = '$val3' WHERE row5 = '$someid' AND active = 'yes')";

mysql_query($query);

This query does nothing. I can not update data.
What am I doing wrong?

Johan
  • 74,508
  • 24
  • 191
  • 319
wyknzo
  • 81
  • 2
  • 10
  • You are not doing any error reporting. Also, look at the final generated query, not the raw PHP. Related: [Reference: What is a perfect code sample using the mysql extension?](http://stackoverflow.com/questions/6198104/reference-what-is-a-perfect-code-sample-using-the-mysql-extension) – Pekka Aug 25 '11 at 12:19
  • The code that you are trying to execute does not make sense. You are trying to set `row1` to one of three values, depending on a condition. But the condition is the same in all three cases. That wil never work. You need to specify three different conditions. Once you have don that use the syntax provided in this answer: http://stackoverflow.com/questions/7190158/php-mysql-multiple-update-do-nothing/7190260#7190260 – Johan Aug 25 '11 at 12:36

3 Answers3

1
UPDATE `table` SET `name`= case `id` 
    when 1 then "Alex"
    when 2 then "John"
    when 3 then "Steve"
 end 
WHERE `id` in(1,2,3)

Isn't it?

TROODON
  • 1,175
  • 1
  • 9
  • 17
1
$sql_string='
UPDATE `TABLE1` SET `row1`= case `id` 
    when 1 then "'.$val1.'"
    when 2 then "'.$val2.'"
    when 3 then "'.$val3.'"
 end 
WHERE `row5 ` in('.$someid.','.$someid.','.$someid.') AND  `active`= "yes"';
mysql_query($sql_string);
TROODON
  • 1,175
  • 1
  • 9
  • 17
1

Add the following code to you php file and you'll understand what's wrong

ini_set('display_errors', 1);
error_reporting(E_ALL);
Pedro Lobito
  • 94,083
  • 31
  • 258
  • 268