简体   繁体   English

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

[英]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. 用户应该猜测一个介于1到99之间的随机,奇数,并且该代码应该同时包含php和HTML代码。

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){

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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