PHP and MySQL, how to update mulitple columns with UPDATE?

mingkus

New Member
I cna't figuire out what is wrong, I use this code<br />
<br />
$query = "UPDATE `accounts` SET (jail) = '$jail', (hospital) = '$hospital', (crime) = '$usercrime' WHERE (username} = '".$_SESSION['myusername']."'";<br />
$result = mysql_query($query);<br />
<br />
but it doesnt seem to work, could someone help me out? Maybe fix up my code a little bit? I have been through many tutorials on the internet, and cant find one that makes sense or that works.<br />
 

Joe

New Member
I don't remember the exact syntax for mysql now, but check the use of the different types of quites ' ` and the brackets ( and } - it doesn't look right to me.

Trying doing a query like this

$query = "UPDATE accounts SET jail = 'somejail', hospital='somehospital', crime = 'somecrime' WHERE username = 'someusername'";
 

MoveeCritic

New Member
If this is the actual code that you are using... take a quick look at your "WHERE" statement, you are using an open parenthesis for username and a closed curly-brace. It looks like a simple typo.

Hope that works for ya....
 

justJR

New Member
Just your syntax (many mistakes)

$query = "UPDATE `accounts` SET ` jail ` = '" . $jail . "' , ` hospital ` = '" . $hospital . "' , ` crime ` = '" . $usercrime . "' WHERE ` username ` = '" . $_SESSION [ ' myusername ' ] . "'" ;
$result = mysql_query($query);

(remove spaces added)
 
Top