Jump to content

Parse error: parse error in C:\xampp\htdocs\attack.php on line 93


Danny620

Recommended Posts

when i run it i get

Parse error: parse error in C:\xampp\htdocs\attack.php on line 93

<?php
require('config.php');
//this file will be all in php
//if user did not select who to attack, we show him list of users
if (!$_GET[attack]) {
//we select id and username of everyone except us
$q = "SELECT id,username FROM test WHERE id<>'$user[id]'";
$battleQ = mysqli_query ($dbc, $q);
while ($battle = mysqli_fetch_array($battleQ)) {
//we show all selected users as well as link to their "attack" subpage
echo "$battle[username] => <a href=\"attack.php?attack=".$battle[id]."\">attack</a> <br>";
}
}

//if user selected link to attack player
if ($_GET[attack]) {
$attack_id = $_GET[attack];
//we check if ID submited is numerical
if (!is_numeric($attack_id)) { die("Bad target ID!"); }
//we select user with that ID
$q = "SELECT * FROM test WHERE id='$user[id]' LIMIT 1";
$attackQ = mysqli_query ($dbc, $q);
$attackR = mysqli_num_rows($attackQ);
//we check that rows are 1. if there are zero rows this means user is modifying link so we close our script!
if ($attackR <> 1) { die("Bad target ID!"); }
//all is fine, we select attacked user
$attack = mysqli_fetch_array($attackQ);
//now we divide weapons to our people
if ($user[weapon3]<=$user[units]) {
//if weapon3 is more or the same of all people, then all people have it
$user_w3 = $user[units];
}else{
//only some users get weapon3
$user_w3 = $user[weapon3];
}
if ($user[weapon2]<=($user[units]-$user_w3)) {
//if weapon2 is more or the same of our people without any weapons, then they have it
$user_w2 = $user[units]-$user_w3;
}else{
//only some users get weapon3
$user_w2 = $user[weapon2];
}

if ($user[weapon1]<=($user[units]-$user_w3-$user_w2)) {
//if weapon1 is more or the same of our people without any weapons, then they have it
$user_w1 = $user[units]-$user_w3-$user_w2;
}else{
//only some users get weapon3
$user_w1 = $user[weapon1];
}

//those are our people without weapons
$user_w0 = $user[units]-$user_w3-$user_w2-$user_w1;

//now we calculate our strength
$user_strength = $user_w0*100 + $user_w1*200 + $user_w2*400 + $user_w3*800;

//We do the same thing for attacked player

//now we divide weapons to attacker
if ($attack[weapon3]<=$attack[units]) {
$target_w3 = $attack[units];
}else{
$target_w3 = $attack[weapon3];
}

if ($attack[weapon2]<=($attack[units]-$target_w3)) {
$target_w2 = $attack[units]-$target_w3;
}else{
$target_w2 = $attack[weapon2];
}

if ($attack[weapon1]<=($attack[units]-$target_w3-$target_w2)) {
$target_w1 = $attack[units]-$target_w3-$target_w2;
}else{
$target_w1 = $attack[weapon1];
}

//those are people who we attacked without weapons
$target_w0 = $attack[units]-$target_w3-$target_w2-$target_w1;

//now we calculate defender strength
$target_strength = $target_w0*100 + $target_w1*200 + $target_w2*400 + $target_w3*800;

//now to calculate casualties; we would divide strength with four (4) and then check the percentage of troops died
$att_cas = $target_strength/4;
$def_cas = $user_strength/4;

//we create formula but see that we have $target_w0 on both sides of / so we can use simple formula
//$target_w0_die = ($def_cas/$target_w0*100)*$target_w0;
$target_w0_die = ($def_cas/100);
//we cannot have more death people then we have
if ($target_w0_die >) { $target_w0_die=$target_w0; } 
$target_w1_die = ($def_cas/200);
if ($target_w1_die >) { $target_w1_die=$target_w1; }
$target_w2_die = ($def_cas/400);
if ($target_w2_die >) { $target_w2_die=$target_w2; }
$target_w3_die = ($def_cas/800);
if ($target_w3_die >) { $target_w3_die=$target_w3; }
$target_killed = $target_w0_die+$target_w1_die+$target_w2_die+$target_w3_die;

//the same for our troops
$user_w0_die = ($att_cas/100);
if ($user_w0_die >) { $user_w0_die=$user_w0; }
$user_w1_die = ($att_cas/200);
if ($user_w1_die >) { $user_w1_die=$user_w1; }
$user_w2_die = ($att_cas/400);
if ($user_w2_die >) { $user_w2_die=$user_w2; }
$user_w3_die = ($att_cas/800);
if ($user_w3_die >) { $user_w3_die=$user_w3; }
$user_killed = $user_w0_die+$user_w1_die+$user_w2_die+$user_w3_die;

//we have two options
//attacker won
if ($user_strength > $target_strength) {
echo "Your troops won. You lost $user_killed units! You managed to plunder $attack[money] money.";

//we update attacker and defender, add money to attacker
$q = "UPDATE test SET money=money+'$attack[money]', units=units-'$user_killed' WHERE id='$user[id]'";
$r = mysqli_query ($dbc, $q);
$q = "UPDATE test SET money='0', units=units-'$target_killed' WHERE id='$attack[id]'";
$r = mysqli_query ($dbc, $q);
}

//defender won
if ($user_strength <= $target_strength) {
echo "Enemy troops were too strong. You lost $user_killed units!";

//we update attacker and defender
$q = "UPDATE test SET units=units-'$user_killed' WHERE id='$user[id]'";
$r = mysqli_query ($dbc, $q);
$q = "UPDATE test SET units=units-'$target_killed' WHERE id='$attack[id]'";
$r = mysqli_query ($dbc, $q);
}

}
?>

All these lines have errors. You are not comparing a value.

if ($target_w0_die >) { $target_w0_die=$target_w0; } 
if ($target_w1_die >) { $target_w1_die=$target_w1; }
if ($target_w2_die >) { $target_w2_die=$target_w2; }
if ($target_w3_die >) { $target_w3_die=$target_w3; }

if ($user_w0_die >) { $user_w0_die=$user_w0; }
if ($user_w1_die >) { $user_w1_die=$user_w1; }
if ($user_w2_die >) { $user_w2_die=$user_w2; }
if ($user_w3_die >) { $user_w3_die=$user_w3; }

You need a value to evaluate the greater than operator

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.