What have i done....

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
rockinliam
Posts: 466
Joined: Sun Jun 07, 2009 11:26 am

What have i done....

Post by rockinliam »

Rebuilding my matchsticks game... getting the error:

Code: Select all

Parse error: syntax error, unexpected T_ELSE in G:\Apps\XAMPP\xampplite\htdocs\matches-two\outcome.php on line 47
INDEX.PHP

Code: Select all

<?php
    session_start();
    if (isset ($_SESSION['total']))
    {
       $total=$_SESSION['total'];
    }
    else
    {
    $_SESSION['total']=21;
    $total=$_SESSION['total'];
	$playerwin = "0";
    }
    ?>
    <?php
	
	if ( $playerwin == "1" ) {
		echo "What are you doing? You won... Go away";
		exit;
	}
	else 
{

    echo "Matches remaining: $total";
	}
?>
    <html>
   <body>
   <br>
    <a href='pickup.php'>PLAY!</a>
      </body>
    </html>
PICKUP.PHP

Code: Select all

<?php
session_start();
    if (isset ($_SESSION['total']))
    {
       $total=$_SESSION['total'];
    }
    else
    {
       echo "A disaster has occured, run away, save yourself!";
       exit;
    }
	include 'computer.php';
$computerminus = $total - $computer;
if ($playerwin == "1") {
	echo "YOU WIN!";
    unset ($_SESSION['total']);
    $_SESSION['total']=21;
    echo "<a href='index.php'>Replay?</a>";
    exit;
}


unset ($_SESSION['total']);
    $_SESSION['total']=$computerminus;
    $total=$_SESSION['total'];
	
echo " Computer took:'$computer' <br>";
echo " Remaining matches:'$computerminus' ";

?>

 <form action="outcome.php" method="post">
    Enter a number between 1 and 3: <input type="text" name="playerinput" size="1" />
        <input type="submit" value="submit" name="submit"  />
        </form>
COMPUTER.PHP

Code: Select all

<?php
if (isset ($_SESSION['total']))
    {
       $total=$_SESSION['total'];
    }
if ($total == "3") {
	$comptake = "2";
}
if ($total =="2") {
	$comptake = "1";
}
if ($total == "1") {
	$playerwin = "1";
	exit;
}

else 
{
	$comptake = array("1" , "2" , "3");
	$comptake = rand (1,3);
}
$computer = $comptake;

echo "$comptake";
?>	
OUTCOME.PHP

Code: Select all

<?php
    session_start();

    if (isset ($_SESSION['total']))
    {
       $total=$_SESSION['total'];
    }
    else
    {
       echo "A disaster has occured, run away, save yourself!";
       exit;
    }

    $player=$_POST['playerinput'];
    $player=strip_tags($player);
	
	$playertake = $total - $player ;
	
    if ($total > "1")
    {
    if (is_numeric ($player))
    {
    if ($player > "3")
    {
    echo "You picked up to many matches!<br>";
    echo "<a href='pickup.php'>Return</a>";
    exit;
    }
    if ($player < "1")
    {
    echo "You picked up to few matches!<br>";
    echo "<a href='pickup.php'>Return</a>";
    exit;
    }
	echo "Matches remaining: $playertake <br> ";
    echo "<a href='pickup.php'>Return</a>";
    unset ($_SESSION['total']);
    $_SESSION['total']=$playertake;
    $total=$_SESSION['total'];
	}
    else
    {
    echo "You used letters.</a>";
    echo "<a href='pickup.php'>Return</a>";
    exit;
    }
	else
    {
    echo " You lose!";
    unset ($_SESSION['total']);
    $_SESSION['total']=21;
    echo "<a href='index.php'>Replay?</a>";
    exit;
    }
	}
    ?>
I'm sure i have made many mistakes...
Skillset: C/C++, OpenGL, C#, Lua, PHP, MySql, Web Dev etc.
Website: https://liam-griffiths.co.uk/
Zyviel
Posts: 75
Joined: Tue Jun 08, 2010 8:12 pm

Re: What have i done....

Post by Zyviel »

rockinliam wrote:Rebuilding my matchsticks game... getting the error:

Code: Select all

Parse error: syntax error, unexpected T_ELSE in G:\Apps\XAMPP\xampplite\htdocs\matches-two\outcome.php on line 47
OUTCOME.PHP

Code: Select all

<?php
    session_start();

    if (isset ($_SESSION['total']))
    {
       $total=$_SESSION['total'];
    }
    else
    {
       echo "A disaster has occured, run away, save yourself!";
       exit;
    }

    $player=$_POST['playerinput'];
    $player=strip_tags($player);
	
	$playertake = $total - $player ;
	
    if ($total > "1")
    {
    if (is_numeric ($player))
    {
    if ($player > "3")
    {
    echo "You picked up to many matches!<br>";
    echo "<a href='pickup.php'>Return</a>";
    exit;
    }
    if ($player < "1")
    {
    echo "You picked up to few matches!<br>";
    echo "<a href='pickup.php'>Return</a>";
    exit;
    }
	echo "Matches remaining: $playertake <br> ";
    echo "<a href='pickup.php'>Return</a>";
    unset ($_SESSION['total']);
    $_SESSION['total']=$playertake;
    $total=$_SESSION['total'];
	}
    else
    {
    echo "You used letters.</a>";
    echo "<a href='pickup.php'>Return</a>";
    exit;
    }
	else
    {
    echo " You lose!";
    unset ($_SESSION['total']);
    $_SESSION['total']=21;
    echo "<a href='index.php'>Replay?</a>";
    exit;
    }
	}
    ?>
I'm sure i have made many mistakes...

Code: Select all

<?php

session_start();

if (isset ($_SESSION['total']))
{
    $total=$_SESSION['total'];
}
else
{
    echo "A disaster has occured, run away, save yourself!";
    exit;
}

$player=$_POST['playerinput'];
$player=strip_tags($player);

$playertake = $total - $player ;

if ($total > "1")
{
    if (is_numeric ($player))
    {
        if ($player > "3")
         {
            echo "You picked up to many matches!<br>";
           echo "<a href='pickup.php'>Return</a>";
           exit;
         }
         if ($player < "1")
          {
           echo "You picked up to few matches!<br>";
            echo "<a href='pickup.php'>Return</a>";
            exit;
        }
        echo "Matches remaining: $playertake <br> ";
        echo "<a href='pickup.php'>Return</a>";
        unset ($_SESSION['total']);
        $_SESSION['total']=$playertake;
        $total=$_SESSION['total'];
    }
    else
    {
        echo "You used letters.</a>";
        echo "<a href='pickup.php'>Return</a>";
        exit;
    }
else
{
    echo " You lose!";
    unset ($_SESSION['total']);
    $_SESSION['total']=21;
    echo "<a href='index.php'>Replay?</a>";
    exit;
}
}
?>

It looks to me like you have an extra bracket at the end.
User avatar
Chris
Posts: 1581
Joined: Wed Sep 30, 2009 7:22 pm

Re: What have i done....

Post by Chris »

A good tip would be to indent your code. That way it's really easy to debug.

so rather than doing this:

Code: Select all

if( $var == $var ) {
if( $var == $var ) {
echo 'lol';
}
}
 
do this:

Code: Select all

if( $var == $var )
{
    if( $var == $var )
    {
        echo 'lol';
    }
}
 
Fighting for peace is declaring war on war. If you want peace be peaceful.
Post Reply

Return to “Advanced Help and Support”