Hi all. Im a PHP Noob, and i suppose a bit of a fool. I undertook a project in PHP for college, but jumped into the deep end. Basically i wanted to make a simple text based war game based on kingsofchaos. I neglected it a bit though, and need help. Here is one of my scripts-
<?
(!defined('')) ? die : '';
session_start();
(!isset($_SESSION['user_id'])) ? redirect('index.php?mode=login') : '';
$set = (isset($HTTP_GET_VARS['set'])) ? $HTTP_GET_VARS['set'] : '';
$target_userid = (isset($HTTP_GET_VARS['uid'])) ? intval($HTTP_GET_VARS['uid']) : redirect('index.php?mode=members');
$user_id=$_SESSION['user_id'];
$uresult = mysql_query("SELECT * FROM users
WHERE user_id=$user_id");
$user=mysql_fetch_assoc($uresult);
$target = mysql_query("SELECT * FROM users
WHERE user_id = '".$target_userid."'");
$target = mysql_fetch_assoc($target);
if ($target_userid == $_SESSION['user_id'])
{
echo 'You cannot attack yourself';
timed_redirect('index.php?mode=attack&set=no', 2);
die;
}
echo 'Maximum ammount: <b>15</b>
<form action="index.php?mode=attack&uid='.$target_userid.'" method="POST">
Turns: <input type="int" name="Turns" size="10"name="att_turns" />:<br />
<input type="submit" value="submit" name="submit"/>
</form>
//attack turns entered here
$attack_turns = (isset($HTTP_POST_VARS['att_turns'])) ? intval($HTTP_POST_VARS['att_turns']): redirect('index.php?mode=members') ;
//attack turns stored in variable
if ($user['user_turns'] >= $attack_turns)
{
if ($attack_turns > 0 && $attack_turns <= 15)
{
if ($user['user_attack_rating'] > $target['user_defence_rating'])
{
$spoils = round(((4.3 * ($target['user_gold']/100)) * $user_turns));//gold to be taken from target
echo'!!! '.$user['user_turns'].'<br>';
echo'!!'.$attack_turns.'<br>';
echo '!!'.$user_turns.'<br>';//debugs to check that data is getting read in
$user_result = mysql_query("UPDATE users
SET user_gold = '".$user_gold+$spoils."',user_turns='".$user_turns-$attack_turns."'
WHERE user_id = '".$_SESSION['user_id']."'");
$target_result = mysql_query("UPDATE users
SET user_gold = '".$target_gold-$spoils."'
WHERE user_id = '".$target_userid."'");
//the aboe user_result and target_result, they not working. not sure if i have set up variables correctly.
$victory = true;
$outcome = 'Victory';
echo "Your troops demolish $target' s army, victory is yours" ;
echo '<br>You have gained:<br><b>'.$spoils.' Gold</b><br><b></b>';
} else {
$victory = false;
$outcome = 'Defeat';
echo '!! '.$target.' s army beats back your army in a humiliating defeat!' ;
$user_resultd = mysql_query("UPDATE users
SET user_turns='".$user_turn-$attack_turns."'
WHERE user_id = '".$_SESSION['user_id']."'");
}
$result = mysql_query("INSERT INTO `attack_log` VALUES ('".$_SESSION['username']."', '".$target['username']."', '".$user['user_attack_rating']."', '".$target['user_def_rating']."', '".$outcome."', '".$spoils."')");
if ($result)
{
echo 'Attack Log Updated!';
//the following are debugs
if($user_result)
{
echo'user Stats updated';
timed_redirect('index.php?mode=main', 10);
} else {
echo'user stat update failed';
timed_redirect('index.php?mode=main', 10);
}
if($user_resultd)
{
echo'user Stats updated';
timed_redirect('index.php?mode=main', 10);
} else {
echo'user stat update failed';
timed_redirect('index.php?mode=main', 10);
}
if($target_result)
{
echo'target Stats updated';
timed_redirect('index.php?mode=main', 10);
} else {
echo'target stat update failed';
timed_redirect('index.php?mode=main', 10);
}
}
}
}else{
echo 'You do not have enough turns';
timed_redirect('index.php?mode=attack', 3);
}
?>
I get this error- "Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in /home2/ronares/public_html/actions/attack.php on line 25
"
Some fresh eyes to glance over it would be greatly appreciated.
Well what this script is to do, is take in attack turns, which are used to attack another user. I fear i am not getting the turns in and not storing them to variable correctly.
If the users attack is greater than the targets defence, a percentage of the targets gold will be taken and added to the users gold. I dont think i am setting up the variables properly or using them properly. If someone could help me on this id be eternaly greatful.