PHP 和 HTML 收音机错误

PHP and HTML Radio error

这是我的代码:

<?php 
$firstQuestion == true;
if($firstQuestion == true) {
 ?>
 <script>alert('firstQuestion is true');</script>
 <h1>1. YES OR NO?</h1>
 <form method="post" action="index.php">
 <input type="radio" name="1" id="yes" class="yes" value="yes" checked="checked"><label for="yes">Yes</label><br>
<input type="radio" name="1" id="no" class="no" value="no"><label for="no">No</label><br>
<input type="submit" name="submit">
</form> <?php
}
if(isset($_POST ['submit'])) {
$firstQuestion == false;
if($_POST ['1'] === 'yes') {
    echo 'Input was recieved as yes';
} else {
    echo 'Input was recieved as no';
}
}

?>
<!DOCTYPE html>
<html>
<head>
</head>
<body>



</body>
</html>

由于某种原因,第一个表格没有出现。 我可以将表格放在正文中,然后使用 javascript 使其消失,但这是一个更大项目的开始,它将根据答案回显更多问题,因此 javascript 方法很多更低效。

您需要将 php 标签中的全部内容放入正文标签 (<body> <?php $firstQuestion = true; //and so on... ?> </body>) 中。所以浏览器可以渲染这个DOM结构。当你编码 HTML.

时,这是最重要的事情

希望对您有所帮助!