Parse error: syntax error, unexpected T_ELSE
Har den her kode:<?
session_start();
if(!$_SESSION[user_id] > 0) {
header("location:index.php");
exit;
}
$user_data = mysql_query("SELECT * FROM players WHERE id=$_SESSION[user_id]");
?>
<html><head><title>Battle!</title><body>
<?php
/*
* $player1 = id på spiller1
* $player2 = id på spiller2
*
* Spiller 1 angriber først
* udskriver vinder men kan evt. retunere vinderen i stedet...
*/
require_once('connect.php');
$data = mysql_query("SELECT * FROM players WHERE id=$_POST[id]") or die(mysql_error());
$p2_data = mysql_fetch_array($data);
if ( $p2_data["currenthp"] >= 10 );
{
function attack($player1, $player2)
{
$data = mysql_query("SELECT * FROM players WHERE id='$player1'") or die(mysql_error());
$p1_data = mysql_fetch_array($data);
$data = mysql_query("SELECT * FROM players WHERE id='$player2'") or die(mysql_error());
$p2_data = mysql_fetch_array($data);
$p1_hit_chance = $p1_data["hitchance"] - $p2_data["dodgechance"];
$p2_hit_chance = $p2_data["hitchance"] - $p1_data["dodgechance"];
$p1_damage = $p1_data["str"] * $p1_data["attackspeed"];
$p2_damage = $p2_data["str"] * $p2_data["attackspeed"];
while(true) //begynd at slå
{
if(mt_rand(0, 100) <= $p1_hit_chance) //spiller 1 rammer
{
$p2_data["currenthp"] -= $p1_damage;
if($p2_data["currenthp"] < 0) $p2_data["currenthp"] = 0;
mysql_query("UPDATE players SET currenthp = $p2_data[currenthp] WHERE id = '$player2'") or die(mysql_error());
}
if($p2_data["currenthp"] == 0) //spiller 2 død
{
$win = $p1_data;
$lose = $p2_data;
break;
}
if(mt_rand(0, 100) <= $p2_hit_chance) //spiller 2 rammer
{
$p1_data["currenthp"] -= $p2_damage;
if($p1_data["currenthp"] < 0) $p1_data["currenthp"] = 0;
mysql_query("UPDATE players SET currenthp = $p1_data[currenthp] WHERE id = '$player1'") or die(mysql_error());
}
if($p1_data["currenthp"] == 0) //spiller 1 død
{
$win = $p2_data;
$lose = $p1_data;
break;
}
}
mysql_query("UPDATE players SET battleswon = $win[battleswon] + 1 WHERE id = $win[id]") or die(mysql_error());
mysql_query("UPDATE players SET battleslost = $lose[battleslost] + 1 WHERE id = $lose[id]") or die(mysql_error());
echo nl2br($win["accountname"] . " win! " . $lose["accountname"] . " lose!\n");
echo $win["accountname"] . " has " . $win["currenthp"] . " HP left.";
}
} else {
echo "Your opponent does not have enough HP, to be attacked.";
}
attack($_SESSION[user_id], $_POST[id]);
?>
<br><br><br>
<a href="play.php">Return</a>
</body></html>
Og får erroren:
Parse error: syntax error, unexpected T_ELSE in /home/virtual/xsix.dk/public_html/online/attacknow.php on line 75
Ved godt jeg nok bare har stillet det forkert op, eller sat en "}" for lidt, men kan simpelthen ikke finde ud af hvor.
PS. Funktionen virkede fint før jeg satte if og else statementet ind.
På forhånd tak,
Mvh.
XsiX
