简体   繁体   中英

Why is my PHP and HTML code not working?

There is this code that I am trying to write. The user is supposed to guess a random, odd number between 1 and 99 and the code is supposed to include both php and HTML codes.

This is the code I came up with:

<?php

$heading = "Welcome to the guessing game";
$num_to_guess = rand(1,99);
if(!isset($_POST['guess'])){
$message= "Welcome to the guessing game";

} elseif($_POST['guess'] %2==0) {
    $message= "The number you are guessing is not odd!!!";

} elseif($_POST['guess']< $num_to_guess){
    $message= "Your guess is smaller than the secret number";

}elseif($_POST['guess']> $num_to_guess){
    $message= "Your guess is bigger than the secret number";

} else($_POST['guess']= $num_to_guess){
    $message= "You guessed correctly.Now try to guess another number!";
}

?>
<!DOCTYPE html>
<html>
<head>
<title> Guessing Machine </title
</head>
<body>
<form action="" method="POST">
Try to guess the odd number between 1 and 99 
<input type="hidden" name="number" value='value="<?php echo $number; ?>">

<br><br>
<input type="submit" name="check" value="check"/><br><br>
</form>
</body>
</html>

I know that the code is not completely correct, because it is not giving me the expected result. Can anyone tell me what exactly is wrong with my code? I am very confused. Thank you.

用以下代码替换最后一个ELSEIF:

} elseif($_POST['guess']== $num_to_guess){

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM