-
CASE
Based on http://dev.mysql.com/doc/refman/5.0/...statement.html, I think I have to store my query before I run it. How do I store and then execute it?
My code so far produces and error:
PHP Code:
$query = "UPDATE plan SET curacc = case when curacc + 1 >= ddecpt
then 0
else curacc + 1
end,
curwipprice = case when curacc + 1 >= ddecpt
then curwipprice + 1
else curwipprice
end
WHERE id = 'LAMS-ZV90'";
include "connect_to_mysql.php";
echo $query . '<br/>';
mysql_query(" . $query . ") or die(mysql_error());
-
the query looks okay
what was the error?
-
Here's the error I received: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '. UPDATE plan SET curacc = case when curacc + 1 >= ddecpt ' at line 1
I would've posted it earlier, but I didn't think I was close enough for it to matter.
-
your query would be fine if you can track down where that period in front of UPDATE came from, and remove it
i don't do php but my guess is, it came from here --
PHP Code:
mysql_query(" . $query . ") or die(mysql_error());
-
Good guess r937! That did the trick.
That was a nice surprise after mowing the lawn.