MySQL Update Query使用两个参数[关闭]

问题描述:

I am using the following code at the end of a rather lengthy update query (I cut out the rest of the code for readability):

WHERE username = '$username' AND charname = '$charname'"

This function checks that a character belongs to the user and that the function is updating the proper character.

When I try to use the update function on the page, I get the following text:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Myusername' AND charname = 'Mycharacter'' at line 1

Some quick notes:

Myusername is the username for the account that created this character. The code retrieves that through a session variable after the user logs in.

Mycharacter is the name of the character that the user is trying to update. It is retrieved from a text box on the same page when the user clicks the button that activates this function.

I've combed through the MySQL update query that precedes the WHERE pretty thoroughly, and the syntax all seems fine, so I am stumped as to why this doesn't work!

Edit: Just for reference, here is the whole query. Fair warning, it is very long.. and if you are a Fallout fan, you might be able to figure out what I am trying to do ;)

$update = "UPDATE Publicchars 
            SET chargender = '$chargender',
                ruleset = '$ruleset', level = '$level',
                hp = '$hp', ap = '$ap',
                carryweight = '$carryweight', defenses = '$defenses',
                strength = '$strength', perception = '$perception',
                endurance = '$endurance', charisma = '$charisma',
                intelligence = '$intelligence', agility = '$agility',
                luck = '$luck', skills = '$skills',
                perks = '$perks', traits = '$traits',
                implants = '$implants', abilities = '$abilities',
                weapons = '$weapons', armor = '$armor',
                ammo = '$ammo', drugs = '$drugs',
                food = '$food', alcohol = '$alcohol',
                meds = '$meds', items = '$items',
                karma = '$karma', reputation = '$reputation',
                accomplishments = '$accomplishments',
                backstory = '$backstory', notes = '$notes'  
            WHERE username = '".$username."' 
              AND charname = '".$charname."'";

You're missing an ' after $reputation.

Then try:

WHERE username = '$username' AND charname = '$charname'";

This seems to keep my syntax highlighting happy at least...