And an operator not working in a PHP function using MySQL

I use a function with MySQL to change the password, but the AND statement does not work correctly.

 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 the primary key, so give me the correct solution.

+5
source share
1 answer

WHERE user_id = user_id will always evaluate to true (if null is not specified). You must either rename the function parameter so that it does not contradict the column name, or table-qualify a reference to the table column.

+2
source

Source: https://habr.com/ru/post/1238603/


All Articles