Dethman Posted July 14, 2008 Share Posted July 14, 2008 Hey guys I have an error from one of my mysql_query's heres the Error: SQL Error: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 'covertTroops` = `covertTroops` +'0', `wizzards` = `wizzards` +'0', `farmer` = `f' at line 1 Here is the Query: <?php mysql_query("UPDATE `user_users` SET `credits` = `credits` - '$cost', `attackTroops` = `attackTroops` +'$atk',`atkTroops` = `atkTroops` +'$satk', `defenseTroops` = `defenseTroops` +'$def', `defTroops` = `defTroops +'$sdef', `covertTroops` = `covertTroops` +'$spy', `wizzards` = `wizzards` +'$wiz', `farmer` = `farmer` +'$far', `miner` = `miner` +'$cre', `untrainedTroops` = `untrainedTroops` - '$atk'-'$def'-'$spy'-'$satk'-'$sdef'-'$wiz'-'$far'-'$cre' WHERE `userid` = '$userid'") or die("SQL Error:".mysql_error()); ?> and Here is the Entire File: <?php function spyBoost($cost,$id){ $q="UPDATE `user_users` SET `credits` =`credits` - '$cost', `covertLVL` = `covertLVL` +'1' WHERE `userid` = '$id'"; mysql_query($q); header("Location: train.php?strErr=Covert Level Upgraded"); } function birthBoost($amt,$cost,$id){ $q="UPDATE `user_users` SET `credits` =`credits` - '$cost', `birthrate` = `birthrate` +'$amt' WHERE `userid` = '$id'"; mysql_query($q); header("Location: train.php?strErr=Birth Rate Upgraded"); } function trainTroops($atk,$satk,$def,$sdef,$spy,$wiz,$far,$cre,$userid){ $sql="SELECT * FROM `user_users` WHERE `userid` = '$userid'"; $query=mysql_query($sql); $player=mysql_fetch_array($query); $atk=floor($atk); $satk=floor($satk); $def=floor($def); $sdef=floor($sdef); $spy=floor($spy); $wiz=floor($wiz); $far=floor($far); $cre=floor($cre); if($cre<=0){ $cre=0; } if($far<=0){ $far=0; } if($wiz<=0){ $wiz=0; } if($spy<=0){ $spy=0; } if($sdef<=0){ $sdef=0; } if($def<=0){ $def=0; } if($satk<=0){ $satk=0; } if($atk<=0){ $atk=0; } if($player['untrainedTroops']-($atk+$satk+$def+$sdef+$spy+$wiz+$far+$cre)>=0){ if($player['credits']-((($atk+$def)*3000)+($spy*5000)+($satk+$sdef*89000)+($wiz*5500)+($far*5000)+($cre*1500))>=0){ $cost=$spy*5000; $cost+=($atk+$def)*3000; $cost+=($satk+$sdef)*89000; $cost+=$wiz*5500; $cost+=$far*5000; $cost+=$cre*1500; mysql_query("UPDATE `user_users` SET `credits` = `credits` - '$cost', `attackTroops` = `attackTroops` +'$atk',`atkTroops` = `atkTroops` +'$satk', `defenseTroops` = `defenseTroops` +'$def', `defTroops` = `defTroops +'$sdef', `covertTroops` = `covertTroops` +'$spy', `wizzards` = `wizzards` +'$wiz', `farmer` = `farmer` +'$far', `miner` = `miner` +'$cre', `untrainedTroops` = `untrainedTroops` - '$atk'-'$def'-'$spy'-'$satk'-'$sdef'-'$wiz'-'$far'-'$cre' WHERE `userid` = '$userid'") or die("SQL Error:".mysql_error()); header("Location: train.php?strErr=TRAINING SUMMARY<br>Troops Trained!"); }else{ header("Location: train.php?strErr=TRAINING SUMMARY<br>Not Enough Magi!"); } }else{ header("Location: train.php?strErr=TRAINING SUMMARY<br>Not Enough Civillians"); } } function untrainTroops($atk,$def,$spy,$userid){ $sql="SELECT * FROM `user_users` WHERE `userid` = '$userid'"; $query=mysql_query($sql); $user=mysql_fetch_array($query); $atk=floor($atk); $def=floor($def); $spy=floor($spy); if($spy<=0){ $spy=0; } if($def<=0){ $def=0; } if($atk<=0){ $atk=0; } if($user['untrainedTroops']-($atk+$def+$spy)>=0){ if($user['credits']-((($atk+$def)*000)+($spy*000))>=0){ $cost=$spy*000; $cost+=($atk+$def)*000; mysql_query("UPDATE `user_users` SET `credits` = `credits` - '$cost', `attackTroops` = `attackTroops` -'$atk', `defenseTroops` = `defenseTroops` -'$def', `covertTroops` = `covertTroops` -'$spys', `untrainedTroops` = `untrainedTroops` + '$atk'+'$def'+'$spy' WHERE `userid` = '$userid'"); header("Location: train.php?strErr=troops trained"); }else{ header("Location: train.php?strErr=not enough credits"); } }else{ header("Location: train.php?strErr=not enough civillians"); } } ?> if you could help soon that would be sweet Thank you all, Brian Flores CEO NimbusGames,llc Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/ Share on other sites More sharing options...
Xurion Posted July 14, 2008 Share Posted July 14, 2008 it looks like you're trying to add a string, not a number: `covertTroops` +'0' Take out the single quotes around the number. Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/#findComment-589548 Share on other sites More sharing options...
vikramjeet.singla Posted July 14, 2008 Share Posted July 14, 2008 try this: <?php mysql_query("UPDATE `user_users` SET `credits` = `credits` - '$cost', `attackTroops` = `attackTroops` +'$atk',`atkTroops` = `atkTroops` +'$satk', `defenseTroops` = `defenseTroops` +'$def', `defTroops` = `defTroops +'$sdef', `covertTroops` = `covertTroops` +'$spy', `wizzards` = `wizzards` +'$wiz', `farmer` = `farmer` +'$far', `miner` = `miner` +'$cre', `untrainedTroops` = `untrainedTroops` - '$atk'-'$def'-'$spy'-'$satk'-'$sdef'-'$wiz'-'$far'-'$cre' WHERE `userid` = '$userid'") or die("SQL Error:".mysql_error()); ?> backqoute is missing in `defTroops` = `defTroops +'$sdef' Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/#findComment-589553 Share on other sites More sharing options...
samshel Posted July 14, 2008 Share Posted July 14, 2008 `defTroops` = `defTroops +'$sdef', Looks like you have missed one back tick after defTroops. It should be `defTroops` = `defTroops` +'$sdef', Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/#findComment-589556 Share on other sites More sharing options...
MasterACE14 Posted July 14, 2008 Share Posted July 14, 2008 it looks like you're trying to add a string, not a number: `covertTroops` +'0' Take out the single quotes around the number. that doesn't matter with MySQL, it interprets it as a number or string automatically. and here's your problem right in the query error message Brian `farmer` = `f' change it to this: `farmer` = 'f' Regards ACE Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/#findComment-589559 Share on other sites More sharing options...
Dethman Posted July 14, 2008 Author Share Posted July 14, 2008 Dude that code you posted is the exact same as the one I posted ??? Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/#findComment-589562 Share on other sites More sharing options...
samshel Posted July 14, 2008 Share Posted July 14, 2008 you code has a back tick before f. Ace code has a single quote. Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/#findComment-589564 Share on other sites More sharing options...
vikramjeet.singla Posted July 14, 2008 Share Posted July 14, 2008 have you gave a try to this?? <?php mysql_query("UPDATE `user_users` SET `credits` = `credits` - '$cost', `attackTroops` = `attackTroops` +'$atk',`atkTroops` = `atkTroops` +'$satk', `defenseTroops` = `defenseTroops` +'$def', `defTroops` = `defTroops +'$sdef', `covertTroops` = `covertTroops` +'$spy', `wizzards` = `wizzards` +'$wiz', `farmer` = `farmer` +'$far', `miner` = `miner` +'$cre', `untrainedTroops` = `untrainedTroops` - '$atk'-'$def'-'$spy'-'$satk'-'$sdef'-'$wiz'-'$far'-'$cre' WHERE `userid` = '$userid'") or die("SQL Error:".mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/#findComment-589565 Share on other sites More sharing options...
JasonLewis Posted July 14, 2008 Share Posted July 14, 2008 When doing things like that I like to do it like this: `field`=(`field`+$number) Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/#findComment-589567 Share on other sites More sharing options...
Dethman Posted July 14, 2008 Author Share Posted July 14, 2008 Guys the code you keep posting is the exact same code I gave you to begin with, exept project fear ill use his method Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/#findComment-589570 Share on other sites More sharing options...
Xurion Posted July 14, 2008 Share Posted July 14, 2008 ` and ' are not the same. Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/#findComment-589572 Share on other sites More sharing options...
Dethman Posted July 14, 2008 Author Share Posted July 14, 2008 Will this work? <?php mysql_query("UPDATE `user_users` SET `credits` =(`credits` -{$cost}), `attackTroops` =(`attackTroops` +{$atk}),`atkTroops` =(`atkTroops` +{$satk}), `defenseTroops` =(`defenseTroops` +{$def}), `defTroops` =(`defTroops +{$sdef}), `covertTroops` = (`covertTroops` +{$spy}), `wizzards` =(`wizzards` +{$wiz}), `farmer` =(`farmer` +{$far}), `miner` = (`miner` +{$cre}), `untrainedTroops` =(`untrainedTroops` - {$atk}-{$def}-{$spy}-{$satk}-{$sdef}-{$wiz}-{$far}-{$cre}) WHERE `userid` = '$userid'") or die("SQL Error:".mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/#findComment-589581 Share on other sites More sharing options...
JasonLewis Posted July 14, 2008 Share Posted July 14, 2008 Your still missing a ` after defTroops. Try this: mysql_query("UPDATE `user_users` SET `credits` =(`credits` -{$cost}), `attackTroops` =(`attackTroops` +{$atk}),`atkTroops` =(`atkTroops` +{$satk}), `defenseTroops` =(`defenseTroops` +{$def}), `defTroops` =(`defTroops` +{$sdef}), `covertTroops` = (`covertTroops` +{$spy}), `wizzards` =(`wizzards` +{$wiz}), `farmer` =(`farmer` +{$far}), `miner` = (`miner` +{$cre}), `untrainedTroops` =(`untrainedTroops` - {$atk}-{$def}-{$spy}-{$satk}-{$sdef}-{$wiz}-{$far}-{$cre}) WHERE `userid` = '$userid'") or die("SQL Error:".mysql_error()); Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/#findComment-589584 Share on other sites More sharing options...
Dethman Posted July 14, 2008 Author Share Posted July 14, 2008 FIXED TY ALL OF YOU! Link to comment https://forums.phpfreaks.com/topic/114652-solved-mysql_error-cant-figure-out-why-its-doing-it-grr/#findComment-589586 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.