0
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).

10
  • 1
    Please stop using mysql_* functions. These extensions have been removed in PHP 7. Learn about prepared statements for PDO and MySQLi and consider using PDO, it's really pretty easy. Commented Feb 9, 2016 at 20:36
  • 1
    If I were to hazard a guess, I would guess that there are errors and you can find them in the error logs. Are you missing some quotes around some values? Commented Feb 9, 2016 at 20:38
  • @JayBlanchard im using phpmyadmin to create tables. im using wamp. :( i dont know how to create tables etc. i dont know anything about PDO :/ Commented Feb 9, 2016 at 20:40
  • 1
    @YusufDevranlı Follow the link to his page, which explains clearly how to use PDO. Commented Feb 9, 2016 at 20:43
  • When mysql_query fails, you should echo mysql_error() to see the reason. Commented Feb 9, 2016 at 20:43

1 Answer 1

1

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)";
Sign up to request clarification or add additional context in comments.

2 Comments

Added how to fix the kill reserved word problem.
Thank you its working i combined both yours and @patrickQ's answers and it worked. i changed {$playergolds[$x]} to '{$playergolds[$x]}' because player gold has "b". and changed kill to kill and i quoted varchars.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.