There is an SQL query I am writing which executes fine when written as below, but it updates all rows.
mysqli_query($connection, 'UPDATE users SET hashed_pass = ' . mysql_escape($newpassword).'');
However, as soon as I attempt to add some logic to it by adding a WHERE statement, I don't get any errors but it is not updating the password for the intended user. I want the statement to update, in this case, user 569 (which is what $user_id is equal to).
mysqli_query($connection, 'UPDATE users SET hashed_pass = ' . mysql_escape($newpassword).' WHERE user_id ='.mysql_escape($user_id).'');
The mysql_escape function just strips slashes and escapes the variable so I know that is not the cause. I also made sure that the table does in fact have the user_id column and the variable $user_id is 569, which matches the user I want to update. After I run the command I don't get any errors and I have an echo statement under the query to confirm that it ran.
Any ideas what I am doing wrong?
Update: As everyone suggested I, converted my code to a prepared statement and it is now working.
$stmt = mysqli_prepare($connection, "UPDATE users SET hashed_pass = ? WHERE user_id = ?");
mysqli_stmt_bind_param($stmt, "si", $newpassword, $user_id);
mysqli_stmt_execute($stmt);