为什么我的PHP和HTML代码不起作用?

时间:2017-12-09 10:37:39

标签: php html

我正在尝试编写这段代码。用户应该猜测1到99之间的随机奇数,代码应该包含php和HTML代码。

这是我提出的代码:

<?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>

我知道代码不完全正确,因为它没有给我预期的结果。谁能告诉我我的代码究竟出了什么问题?我很迷茫。谢谢。

1 个答案:

答案 0 :(得分:0)

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

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