Hi Guys,
Just creating a game which allows the user to guess if the next number is going to be higher or lower (Very simple!)
On looking at the page for the first time the user gets this:
The first card is 5(for example)
Higher
Lower
The user then clicks on the higher or lower button
and should get a result!
I am only getting a blank page
This is the code - Any comments would be welcome!
<?php
$base_card = $_POST['card']; // retrieves previous card
$horl = $_POST['horl']; // retrieves high or low decision
$card = rand('1', '10'); // generates new card
// if first visit
if(empty($base_card))
{
echo "The first card is $card
<form method='POST' action='$PHP_SELF'>
<input type='hidden' name='horl' value='high'>
<input type='hidden' name='card' value='$card'>
<input type=submit value='HIGHER'></form>
<form method='POST' action='$PHP_SELF'>
<input type='hidden' name='horl' value='low'>
<input type='hidden' name='card' value='$card'>
<input type=submit value='LOWER'></form>";
}
// If pair is generated lose
if($base_card == $card)
{
echo "NOTHIN FOR A PAIR<br />
Last card was $base_card New Card is $card You went $horl";
}
//if user selected high and new card is higher than old card
if("$horl" == "high" && "$card" > "$base_card")
{
echo "You win<br /><br />";
echo "The last Card was $base_card and you chose to go $horl and the card was $card
<br /><br />
<form method='POST' action='$PHP_SELF'>
<input type='hidden' name='horl' value='high'>
<input type='hidden' name='card' value='$card'>
<input type=submit value='HIGHER'></form>
<form method='POST' action='$PHP_SELF'>
<input type='hidden' name='horl' value='low'>
<input type='hidden' name='card' value='$card'>
<input type=submit value='LOWER'></form>";
}
//if user selected low and old card is higher than new card
elseif("$horl" == "low" && "$card" < "$base_card")
{
echo "You Lose!<br />
Last card $base_card new card $card you went lower";
}
?>