PHP - MySQL - How to check if value updated or not
I have a php code to update / change value of already existing record like;
$con = mysql_connect("server","username","password");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("database", $con);
$query = mysql_query("UPDATE table SET field1='$newvalue1',
field2='$newvalue2' WHERE key = '$key'") or exit(mysql_error());
echo "true";
I want to echo "true" if data is updated and echo "false" if there is some
syntax error or if record don't exist or something else, where record
value remain unchanged. How can I do this?
Note: I know mysqli* and I prefer it over mysql*, but here for traditional
mysql*
Thanks in advance...:)
No comments:
Post a Comment