Jump to content

[SOLVED] Mysql_error Cant figure out why its doing it GRR


Dethman

Recommended Posts

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

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'

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

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());
?>

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());

?>

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());

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.