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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.