$result=mysql_query(" UPDATE xxxxxx_users SET User_Password='$Password' WHERE FstName='$First' AND LstName='$Last'",$db) or die ("Password update successful!");
echo "Update failed, unknown user";
This correctly updates the db when the first and last names match and the db is not affected when they don't. My only issue is I always display the Update failed, unknown user message. what did I do wrong? Thanks.
The mysql_query function returns true when an SQL query is successful:
For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.
Your code is assuming that the query returns the number of rows effected. Use the mysql_affected_rows function for this purpose:
$result=mysql_query(" UPDATE xxxxxx_users SET User_Password='$Password' WHERE FstName='$First' AND LstName='$Last'",$db)
if (mysql_affected_rows() > 0)
die ("Password update successful!");
else
echo "Update failed, unknown user";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With