douao3063 2016-12-07 23:02
浏览 35
已采纳

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."'";
  • 写回答

1条回答 默认 最新

  • dongxu1029 2016-12-07 23:28
    关注

    You're missing an ' after $reputation.

    Then try:

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

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口