MrUber MrUber - 5 months ago 19
PHP Question

Update multiple columns PHP SQL

I'm trying to update multiple columns at once, and I can't get it to work. It's pretty simple code, no cross table etc.

I've tried

$query1 = "UPDATE person
SET FName = '$fname'
SET LName = '$lname'
WHERE personid=33";


(wich is deffinitely wrong)

and also,

$query1 = "UPDATE person
SET FName = '$fname',
LName = '$lname',
WHERE personid=33";


but I cannot get it to work for the life of me. I'm using phpMyAdmin.

Answer

You had an invalid comma between LName and WHERE. This is recommended on w3schools, which you can refer to if you need further help.

$query1 = "UPDATE person
            SET FName = '$fname',
            LName = '$lname'
            WHERE personid=33";