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

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)";
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题