Could Use Some Help Again

Sounds like a newbie question but im new to php and this is bothering me this is the code I have

        $player_update   = mysqli_query($mysqli, "UPDATE `players` SET money=money+'$win_money', gold=gold+'$win_gold', energy=energy-2, health=health-5, respect=respect+'$win_respect', points=points+'$win_points', turns=turns-10, ghoul=ghoul, werewolf=werewolf, dragon=dragon WHERE id='$player_id'");

AND IM TRYING TO IMPLEMENT THIS CODE

  mysql_query("UPDATE $tab[pimp] SET ghoul=ghoul-$thughs[u_kills], werewolf=werewolf-$hitmans[u_kills], dragon=dragon-$bodyguards[u_kills], money='$u_cash', thugk=thugk+$ak47kills, attout=attout+1, trn=trn-2 WHERE id='$id'");

but it keeps having a syntax error and im not sure when i add the [u_kills] to the update code is there another way to do this that I dont know about because it bugging me. also if intrested im looking for a coder to help me on my website if intrested email me @ [email protected]

CAN someone help me out and give me the right way to make this thing work.???

THIS is the error im recieving from my error log

Stack trace:
#0 /home1/mystica6/public_html/fight-arena.php(381): mysqli_query(Object(mysqli), ‘UPDATE players...') #1 {main} thrown in /home1/mystica6/public_html/fight-arena.php on line 381 [13-Dec-2023 00:13:47 America/Chicago] PHP Fatal error: Uncaught mysqli_sql_exception: 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 '[u_kills]), werewolf=werewolf, dragon=dragon WHERE id='1'' at line 1 in /home1/mystica6/public_html/fight-arena.php:381 Stack trace: #0 /home1/mystica6/public_html/fight-arena.php(381): mysqli_query(Object(mysqli), 'UPDATE players…’)
#1 {main}
thrown in /home1/mystica6/public_html/fight-arena.php on line 381

this is also the code i just added to make the update players make sense, is there something i missed or messed up. Think the server is using php 7 or 8

$ghouls   = array("u_kills" => 0, "h_kills" => 0);
 $werewolfs   = array("u_kills" => 0, "h_kills" => 0);
 $dragons  = array("u_kills" => 0, "h_kills" => 0);
 
  srand(microtime()*time());
 $ghouls   = array("u_kills" => 0, "h_kills" => 0);
 $werewolfs  = array("u_kills" => 0, "h_kills" => 0);
 $dragons   = array("u_kills" => 0, "h_kills" => 0);
 $tempKills = $his_kills;


$limit = 0;
      while($tempKills > 0 && $limit < 20){
      $limit++;
      
   if($ghouls["u_kills"]<0) { $ghouls["u_kills"]=0; }
 if($werewolfs["u_kills"]<0) { $werewolfs["u_kills"]=0; }
 if($dragons["u_kills"]<0) { $dragons["u_kills"]=0; }
 if($rowu['ghoul']>round(1.2*$ghouls["u_kills"])){$ghouls["u_kills"]=round(1.0*$ghouls["u_kills"]);}else{$ghouls["u_kills"]=$rowu['ghoul'];}
 if($rowu['werewolf']>round(0.8*$werewolfs["u_kills"])){$werewolfs["u_kills"]=round(1.0*$werewolfs["u_kills"]);}else{$werewolfs["u_kills"]=$rowu['werewolf'];}
 if($rowu['dragon']>round(0.4*$dragons["u_kills"])){$dragons["u_kills"]=round(1.0*$dragons["u_kills"]);}else{$dragons["u_kills"]=$rowu['dragon'];}      

  $bigNum = (($rowu['ghoul']-$ghouls["u_kills"]) >= $tempKills) ? $tempKills : ($rowu['ghoul']-$ghouls["u_kills"]);
  $temp  = rand(round($bigNum*0.9), $bigNum);
  $ghouls["u_kills"]  += $temp;
  $tempKills    -= $temp;
  
  $bigNum = (($rowu['werewolf']-$werewolfs["u_kills"]) >= $tempKills) ? $tempKills : ($rowu['werewolf']-$werewolfs["u_kills"]);
  $temp  = rand(round($bigNum*0.9), $bigNum);
  $werewolfs["u_kills"]  += $temp;
  $tempKills   -= $temp;

    $bigNum = (($rowu['dragon']-$dragons["u_kills"]) >= $tempKills) ? $tempKills : ($rowu['dragon']-$dragons["u_kills"]);
  $temp  = rand(round($bigNum*0.9), $bigNum);
  $dragons["u_kills"]  += $temp;
  $tempKills    -= $temp;
  
 if((($rowu['ghoul']+$rowu['werewolf']+$rowu['dragon']) - ($ghouls["u_kills"]+$werewolfs["u_kills"]+$dragons["u_kills"])) < 1){
   $tempKills = 0;
  }
 }
 
 $his_kills = $ghouls["u_kills"]+$werewolfs["u_kills"]+$dragons["u_kills"];
 
 $tempKills = $your_kills;
 
  $limit=0;
 while($tempKills > 0 && $limit<20){
  $limit++;

 $bigNum = (($rowuo['redcap']-$redcaps["h_kills"]) >= $tempKills) ? $tempKills : ($rowuo['redcap']-$redcaps["h_kills"]);
  $temp  = rand(round($bigNum*0.9), $bigNum);
  $redcaps["h_kills"]  += $temp;
  $tempKills    -= $temp;

  $bigNum = (($rowuo['centaur']-$centaurs["h_kills"]) >= $tempKills) ? $tempKills : ($rowuo['centaur']-$centaurs["h_kills"]);
  $temp  = rand(round($bigNum*0.9), $bigNum);
  $centaurs["h_kills"]  += $temp;
  $tempKills   -= $temp;
  
  $bigNum = (($rowuo['fairy']-$fairies["h_kills"]) >= $tempKills) ? $tempKills : ($rowuo['fairy']-$fairies["h_kills"]);
  $temp  = rand(round($bigNum*0.9), $bigNum);
  $fairies["h_kills"]  += $temp;
  $tempKills    -= $temp;

 if((($rowuo['redcap']+$rowuo['centaur']+$rowuo['fairy']) - ($redcaps["h_kills"]+$centaurs["h_kills"]+$fairies["h_kills"])) < 1){
   $tempKills = 0;
  }
 }
 
  if($redcaps["h_kills"]<0) { $redcaps["h_kills"]=0; }
 if($centaurs["h_kills"]<0) { $centaurs["h_kills"]=0; }
 if($fairies["h_kills"]<0) { $fairies["h_kills"]=0; }
 if($redcaps['redcap']>round(1.2*$redcaps["h_kills"])){$redcaps["h_kills"]=round(1.0*$redcaps["h_kills"]);}else{$redcaps["h_kills"]=$rowuo['redcap'];}
if($rowuo['centaur']>round(0.8*$centaurs["h_kills"])){$centaurs["h_kills"]=round(1.0*$centaurs["h_kills"]);}else{$centaurs["h_kills"]=$rowuo['centaur'];}
 if($rowuo['fairy']>round(0.4*$fairies["h_kills"])){$fairies["h_kills"]=round(1.0*$fairies["h_kills"]);}else{$fairies["h_kills"]=$rowuo['fairy'];}
 
 $your_kills = $redcaps["h_kills"]+$centaurs["h_kills"]+$fairies["h_kills"];

does this make sense???

The sql error concerns a modification to the first query, but you didn’t post the actual code/query that produces the error.

You need to review the list of programming practices I posted in your previous thread. That list was given to help organize, secure, and simplify the code, making it easier to design, write, test, and debug code and query(ies.)

im working off a already premaid script im just modifying and adding new things to it/ adjusting things also I understand im a newbie but im just trying to figure out why when i first i added this code it did subtract something from the units that are in my game but then I did something and now it just stays stuck i figured either it was because the UPDATE part is not recognizing the right format to make the ghouls update what is supposed to be happeneing, maybe its just best I hire a coder to do this stuff.

Unless you are running an ancient version of PHP, this shouldn’t work to begin with, FYI.

Use Curly braces in double quotes
“UPDATE {$blah[blag]}”
Especially when it comes to arrays like you have…

Sponsor our Newsletter | Privacy Policy | Terms of Service