Skip to content
Advertisement

UPDATE MySQL record of selected value from dropdown list

I’m just learning MySQL/PHP and I’m trying to update a mysql record of a selected value from the dropdown list. I have read through several tutorials, and tried to apply them, but I cannot get this working…

What I want : I got a dropdown list with two options (Approved, Disapproved). I want to UPDATE the selected value from the dropdown menu to the specific user using its user_id.

Problem: When I change the SQL query from WHERE user_id = ‘$user_id’ to WHERE user_id = 75 it will update the record with id 75. So it has something to do with that.

JavaScript

Advertisement

Answer

You need to pass the user_id via a hidden field in the form to be able to update a specific user.

JavaScript

Then your query becomes (is sql injectable):

JavaScript

While you say you’re not concerned with sql injection, to protect the query you can replace the code with the following which will protect it against sql injection:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement