dro44817 2016-02-09 20:34
浏览 45
已采纳

mysql_query不起作用并给出错误

while($x < 10)
    {
    $str = "( NULL, '{$players[$x]}', '1' , 0 + {$sonucs[$x]},oynananoyun - win,'{$rols[$x]}','{$teams[$x]}','{$playerkills[$x]}','{$playerdeaths[$x]}','{$playerassists[$x]}','{$creeps[$x]}','{$dmgs[$x]}','{$dpms[$x]}','{$wards[$x]}','{$playergolds[$x]}','{$gpms[$x]}', '{$goldpercantages[$x]}', 0 + {$fbs[$x]},'{$dmgpercantages[$x]}', '{$wardscleared[$x]}', '{$wpm[$x]}', '{$wcpm[$x]}','{$wardpercents[$x]}', '{$wardsclearedpercents[$x]}', '{$cspms[$x]}')";
    $yaya = "kill = kill + {$playerkills[$x]}, death = death + {$playerdeaths[$x]},assist = assist + {$playerassists[$x]},cs = cs + {$creeps[$x]}, cspm = cspm + {$cspms[$x]}, takim = {$teams[$x]}, dmg = dmg + {$dmgs[$x]}, dpm = dpm + {$dpms[$x]},wardplaced = wardplaced + {$wards[$x]}, oynananoyun = oynananoyun + 1, win = win + {$sonucs[$x]}, rol = {$rols[$x]}, gold = gold + {$playergolds[$x]}, goldshare = goldshare + {$goldpercantages[$x]}, gpm = gpm + {$gpms[$x]}, fb = fb + {$fbs[$x]}, dmgshare = dmgshare + {$dmgpercantages[$x]}, wardcleared = wardcleared + {$wardscleared[$x]}, wardplacedpm = wardplacedpm + {$wpm[$x]}, wardclearedpm = wardclearedpm + {$wcpm[$x]}, wardplacedshare = wardplacedshare + {$wardpercents[$x]}, wardclearedshare = wardclearedshare + {$wardsclearedpercents[$x]}";
    mysql_query ("INSERT INTO playerstats18 (`id`,`player`,`oynananoyun`,`win`,`lose`,`rol`,`takim`,`kill`,`death`,`assist`,`cs`,`dmg`,`dpm`,`wardplaced`,`gold`,`goldshare`,`gpm`,`fb`,`dmgshare`,`wardcleared`,`wardplacedpm`,`wardclearedpm`,`wardplacedshare`,`wardclearedshare`,`cspm`) VALUES $str ON DUPLICATE KEY UPDATE $yaya");
    $x++;
    }

mysql_query was working but then i added more values at $yaya and its not working now. Im not missing any commas, I checked it. Its not updating or inserting.

" 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 'kill = kill + 0, death = death + 1,assist = assist + 14,cs = cs + 28, cspm = csp' at line 1 "

'kill = kill + 0, death = death + 1,assist = assist + 14,cs = cs + 28, cspm = csp' at line 1

What $yaya loooks like

kill = kill + 0, death = death + 1,assist = assist + 14,
cs = cs + 28, cspm = cspm + 1, takim = DP,
dmg = dmg + 3.0, dpm = dpm + 110,wardplaced = wardplaced + 43,
oynananoyun = oynananoyun + 1, win = win + 1 , rol = Support,
gold = gold + 7.7b, goldshare = goldshare + 14.1,
gpm = gpm + 283, fb = fb + 0,
dmgshare = dmgshare + 6.4, wardcleared = wardcleared + 9,
wardplacedpm = wardplacedpm + 1.58,
wardclearedpm = wardclearedpm + 0.33,
wardplacedshare = wardplacedshare + 29.6,
wardclearedshare = wardclearedshare + 31

enter image description here

edit: i changed yaya string to

$yaya = "`kill` = `kill` + {$playerkills[$x]}, 
death = death + {$playerdeaths[$x]},
assist = assist + {$playerassists[$x]},
cs = cs + {$creeps[$x]}, 
cspm = cspm + {$cspms[$x]}, 
takim = '{$teams[$x]}', 
dmg = dmg + {$dmgs[$x]}, 
dpm = dpm + {$dpms[$x]},
wardplaced = wardplaced + {$wards[$x]}, 
oynananoyun = oynananoyun + 1, 
win = win + {$sonucs[$x]}, 
rol = '{$rols[$x]}', 
gold = gold + '{$playergolds[$x]}', 
goldshare = goldshare + {$goldpercantages[$x]}, 
gpm = gpm + {$gpms[$x]}, fb = fb + {$fbs[$x]}, 
dmgshare = dmgshare + {$dmgpercantages[$x]}, 
wardcleared = wardcleared + {$wardscleared[$x]}, 
wardplacedpm = wardplacedpm + {$wpm[$x]}, 
wardclearedpm = wardclearedpm + {$wcpm[$x]}, 
wardplacedshare = wardplacedshare + {$wardpercents[$x]}, 
wardclearedshare = wardclearedshare + {$wardsclearedpercents[$x]}";

I changed kill to kill, {$playergolds[$x]} to '{$playergolds[$x]}' because it has "b" (6.6b forexample and quoted varchars (not sure if it was necessary).

  • 写回答

1条回答 默认 最新

  • dongyun6229 2016-02-09 20:49
    关注

    Since rol is a VARCHAR, you need quotes around the value.

    rol = {$rols[$x]}
    

    should be:

    rol = '{$rols[$x]}'
    

    You can see this in the value of $yaya:

    rol = Support
    

    it should be

    rol = 'Support'
    

    You wouldn't have problems like this if you used prepared queries with PDO or mysqli.

    The other problem is that kill is a reserved word. To use it as a column name, you need to escape it with backticks:

    `kill` = `kill` + {$playerkills[$x]}
    

    Also, when using ON DUPLICATE KEY UPDATE, you don't need to repeat all the values from the VALUES list. You can write

    rol = VALUES(rol)
    

    which means that the update should use the same value that would have been inserted if there wasn't a duplicate key. So you could write:

    $yaya = "`kill` = `kill` + VALUES(`kill`), death = death + VALUES(death), assist = assist + VALUES(assist), 
            cs = cs + VALUES(cs), cspm = cspm + VALUES(cspm), takim = VALUES(takim), dmg = dmg + VALUES(dmg), 
            dpm = dpm + VALUES(dpm), wardplaced = wardplaced + VALUES(wardplaced), 
            oynananoyun = oynananoyun + 1, win = win + VALUES(win), rol = VALUES(rol), 
            gold = gold + VALUES(gold), goldshare = goldshare + VALUES(goldshare), gpm = gpm + VALUES(gpm), 
            fb = fb + VALUES(fb), dmgshare = dmgshare + VALUES(dmgshare), wardcleared = wardcleared + VALUES(wardcleard), 
            wardplacedpm = wardplacedpm + VALUES(wardplacedpm), wardclearedpm = wardclearedpm + VALUES(wardclearedpm), 
            wardplacedshare = wardplacedshare + VALUES(wardplacedshare), wardclearedshare = wardclearedshare + VALUES(wardclearedshare)";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥30 STM32 INMP441无法读取数据
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境