Can you try this?
You placed the '()' in your elseif wrong.
<?php
$rand = rand(1, 99);
$guess = $_POST['guess'];
$submit = $_POST['submit'];
if(isset($submit))
{
if($guess / 2 % 0)
{
echo "the number you are guessing is not odd";
}
elseif($guess < $rand)
{
echo "Your Guess is Smaller than the secret number";
}
elseif($guess > $rand)
{
echo "Your Guess is bigger than the secret number";
}
elseif($guess == $rand)
{
echo "you guessed currectly. now try anouthe number!";
}
}
else
{
header("Location: index.php");
exit();
}
?>
I have not tested this code, so i need your feedback. Edit: You've confirmed this worked.
I'd like to provide you the manual about elseif
:
http://php.net/manual/en/control-structures.elseif.php
Please consider easier/cleaner coding. Personally I like to use ':' instead of '{}', it's less code and easier to read when you use HTML
mixed with PHP
like:
<?php
$rand = rand(1, 99);
$guess = $_POST['guess'];
$submit = $_POST['submit'];
if(isset($submit)):
if($guess / 2 % 0):
echo "the number you are guessing is not odd";
elseif($guess < $rand):
echo "Your Guess is Smaller than the secret number";
elseif($guess > $rand):
echo "Your Guess is bigger than the secret number";
elseif($guess == $rand):
echo "you guessed currectly. now try anouthe number!";
else:
header("Location: index.php");
exit();
endif;
?>
And don't forget to check the $_POST
data.
Same goes for array
, but thats a side note:
$arr = array(1 => 'hi', 2 => 'hello'); // old
$arr = [1 => 'hi', 2 => 'hello']; // new