Update if(condition) or produce an error
I need do an update a table via php. I need the response will be Ok or
Error. Basically, i need substract 1 to the field value, if field value is
not zero. If the field value is zero, i try to force produce an error,
replacing the numeric field with a string value
The SQL statement is:
$query = "Update mytable set myfield = if( myfield > 0 , myfield - 1 ,
'AAA') where cliente_id = $cual_ID";
After this, the php code is:
if (mysql_query($query))
{
echo "OK";
}
else
{
echo "Error 4";
}
mysql_close($link);
When I run the php, it always return OK, also when myfield is greater than
zero.
Any ideas?
No comments:
Post a Comment