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

Isaac Bennetch
  • 11,830
  • 2
  • 32
  • 43
Yusuf Devranlı
  • 159
  • 1
  • 2
  • 8
  • 1
    Please [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). [These extensions](http://php.net/manual/en/migration70.removed-exts-sapis.php) have been removed in PHP 7. Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) statements for [PDO](http://php.net/manual/en/pdo.prepared-statements.php) and [MySQLi](http://php.net/manual/en/mysqli.quickstart.prepared-statements.php) and consider using PDO, [it's really pretty easy](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Feb 09 '16 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? – Jay Blanchard Feb 09 '16 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 :/ – Yusuf Devranlı Feb 09 '16 at 20:40
  • 1
    @YusufDevranlı Follow the link to his page, which explains clearly how to use PDO. – Barmar Feb 09 '16 at 20:43
  • When `mysql_query` fails, you should `echo mysql_error()` to see the reason. – Barmar Feb 09 '16 at 20:43
  • @Barmar it says "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 " – Yusuf Devranlı Feb 09 '16 at 20:46
  • `kill` is a [reserved word](https://dev.mysql.com/doc/refman/5.5/en/keywords.html) – Patrick Q Feb 09 '16 at 20:48
  • @PatrickQ what should i do? i replaced kill to `kill` at $yaya but it says "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 'b, goldshare = goldshare + 14.1, gpm = gpm + 283, fb = fb + 0, dmgshare = dmgsha' at line 1" now – Yusuf Devranlı Feb 09 '16 at 20:54
  • That's because `7.7b` is not a number – Patrick Q Feb 09 '16 at 20:55
  • @PatrickQ thank you very much its working now! i changed {$playergolds[$x]} to '{$playergolds[$x]}' – Yusuf Devranlı Feb 09 '16 at 21:01

1 Answers1

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)";
Barmar
  • 741,623
  • 53
  • 500
  • 612
  • Added how to fix the `kill` reserved word problem. – Barmar Feb 09 '16 at 20:59
  • 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. – Yusuf Devranlı Feb 09 '16 at 21:03