Help with an update query

I’m trying to make a page that updates the member list of my website, but for some reason it doesn’t actually update it. This is the code I’m using:

UPDATE member
SET username=$updateuser,password=$updatepass,email=$updatemail
WHERE id=$i;"

$i is the iteration number, and it gets the variables every time. I’ve echoed stuff onto the page to test that they work, and yes, all of my variables do. So why doesn’t the query work?

Thanks for any help you have! =)

Can you echo this on the page and show us the results…

echo "UPDATE member SET username=$updateuser,password=$updatepass,email=$updatemail WHERE id=$i;"

The syntax looks correct…

Well from the looks of your code, It seems you are missing ’ ’ when enclosing strings (VARCHARs). I have updated it hope it will work for you. It would be a lot better for you, if you implement a check on your query to see if its working or not. Anyways here is the code.

[php] $query = "UPDATE member

				username = '{$updateuser}',
				password = '{$updatepass}',
				email = '{$updatemail}'


				id = $i


There are 53 users so it’s a lengthy result. I’ll just give you mine, since this isn’t my usual password:

UPDATE member SET username=Aari,password=snowman,[email protected] WHERE id=2

When you run that directly in the database does it work?


@tanzeelniazi is correct, you need to put quotes around those because they are varchar fields.

Okay, I changed it to:

[php]$query = “UPDATE member SET username=’$updateuser’,password=’$updatepass’,email=’$updatemail’ WHERE id=’$i’”

I’m assuming that’s what you meant by quotes around those. I don’t know why you said {}'s in them, but I tried that too and it didn’t work.

And now that I’ve switched the query to a variable, it doesn’t like it at all. It’s popping out an error, saying that

Parse error: syntax error, unexpected T_STRING
on the line of the msql_query.

The curly braces ensures that PHP treat it like a variable.

From your code it seems that you haven’t used a semicolon at the end of the string i.e. on the first line.
and one more thing and the $i variable will most probably be an INT therefore you don’t need singles quotes to enclose it.

Okay, I tried running the code from the actual server and it worked perfectly. So there’s nothing wrong with it. In what cases is an update query unable to work? Because the code works wonderfully. xD

It’s working now, turns out I was missing a db selection. Thanks for your time!

Sponsor our Newsletter | Privacy Policy | Terms of Service