I am using a function with MySQL to change password but the AND
operator is not working properly.
CREATE DEFINER = 'root'@'%'
FUNCTION temp_staff.fn_changePassword(user_id INT, oldPassword VARCHAR(255), newPassword VARCHAR(255))
RETURNS int(11)
BEGIN
update temp_staff.tbl_user set password = newPassword WHERE user_id = user_id AND password = oldPassword;
RETURN 1;
END
Result: it fetches 3 rows but in my table user_id is primary key, so give me proper solution.
WHERE user_id = user_id
will always evaluate to true (unless null). You should either rename the function parameter so that it doesn't conflict with the column name, or else table-qualify the reference to the table column.
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