Jump to content

[SOLVED] Parse error: parse error, expecting `','' or `';'' in C:\xampp\htdocs\attack.php


Danny620

Recommended Posts

when i run it i just get Parse error: parse error, expecting `','' or `';'' in C:\xampp\htdocs\attack.php on line 22

 

<?php require('config.php'); ?>
<style type="text/css">
<!--
body,td,th {
color: #FFFFFF;
}
body {
background-color: #000000;
}
-->
</style><?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,clan,wins,lose FROM test WHERE id<>'$user[id]'";
$battleQ = mysqli_query ($dbc, $q);
echo '<table width="698" border="0" align="center">';
while ($battle = mysqli_fetch_array($battleQ)) {
//we show all selected users as well as link to their "attack" subpage
echo "<tr>
    <td width="279"><div align="center">$battle[username]</div></td>
    <td width="206"><div align="center">$battle[clan]</div></td>
    <td width="55"><div align="center"><a href=\"profile.php?profile=".$battle[username]."\">attack</a></div></td>
    <td width="68"><div align="center">$battle[wins]</div></td>
    <td width="68"><div align="center">$battle[lose]</div></td>
  </tr>";
}
echo '</table>';
}

//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='$attack_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);
if($user[turns] <= 0){die("You Have Ran Out of TURNS!!");}

if($user[units] >= $attack[units]){
srand(time());
$random = (rand()%5)+1;
echo "Well done you owned that NOOB!! ";
$cashgain = floor($pot[cashpot] / $random);
echo "You GAINED $cashgain gp";
$q = "UPDATE test SET money=money+'$cashgain', turns=turns-'1', wins=wins+'1' WHERE id='$user[id]'";
$r = mysqli_query($dbc, $q);
$q = "INSERT INTO reports (id, username, message, outcome) VALUES ('$attack[id]', '$user[username]', 'The attacker Won and gained $cashgain gp','You lose')";
$r = mysqli_query($dbc, $q);
}else{
echo "BETTER LUCK NEXT TIME YOU JUST GOT OWNED!!!";
$q = "UPDATE test SET turns=turns-'1', lose=lose+'1' WHERE id='$user[id]'";
$r = mysqli_query($dbc, $q);
$q = "INSERT INTO reports (id, username, message, outcome) VALUES ('$attack[id]', '$user[username]', 'You Won','You Won')";
$r = mysqli_query($dbc, $q);
}
}
?>
<table width="698" border="0" align="center">
  <tr>
    <td width="279"><div align="center">Username</div></td>
    <td width="206"><div align="center">Alliance</div></td>
    <td width="55"><div align="center">Attack</div></td>
    <td width="68"><div align="center">Wins</div></td>
    <td width="68"><div align="center">Loses</div></td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
</table>

You have to add a backslash  ->

\

 

To all the quotation marks ->

"
inside the echo " ";

 

Or else you close the echo.

OR, you can use single quotation marks ->

'
for the echo statement, like this echo ' ';

 

But then you must wrap variables with these ->

{}

You need to be escaping the double quotes (\") within this block of code.

echo "<tr>
    <td width="279"><div align="center">$battle[username]</div></td>
    <td width="206"><div align="center">$battle[clan]</div></td>
    <td width="55"><div align="center"><a href=\"profile.php?profile=".$battle[username]."\">attack</a></div></td>
    <td width="68"><div align="center">$battle[wins]</div></td>
    <td width="68"><div align="center">$battle[lose]</div></td>
  </tr>";

 

Remember if you start your strings with a double quote. You must escape them within your string.

echo "
<tr>
    <td width=\"279\"><div align=\"center\">$battle[username]</div></td>
    <td width=\"206\"><div align=\"center\">$battle[clan]</div></td>
    <td width=\"55\"><div align=\"center\">
<a href=\"profile.php?profile=".$battle[username]."\">attack</a></div></td>
    <td width=\"68\"><div align=\"center\">$battle[wins]</div></td>
    <td width=\"68\"><div align=\"center\">$battle[lose]</div></td>
</tr>
  ";

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.