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 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等