PHP简单的数学问答程序

PHP简单的数学问答程序

问题描述:

我正在尝试创建一个数学测验页面。第一页需要生成一个显示为标题的问题,该问题询问用户将两个随机数相乘在一起。
然后根据用户的输入,将它们带到不同的页面。
如果它们正确,则显示段落你是对的!。
如果他们错了,它会显示段落你是不正确的,并邀请用户再试一次。
,如果他们输入字符串,则会显示段落我不明白您的回复,并邀请用户再次尝试。

I'm trying to create a maths quiz page. The first page needs to generate a question shown as a header, that asks the user what two random numbers are multiplied together. Then depending on the users input, it takes them to a different page. If they are correct it displays the paragraph "You are correct!". If they are wrong it displays the paragraph "You are incorrect" and invites the user to try again. and if they enter a string it displays the paragraph "I don't understand your response" and invites the user to try again.

到目前为止,我拥有下面的代码,布局是正确的,但标题不起作用,并且我试图显示一个新页面,但是再次,他们不加载。

So far I have the below code, the layout is correct but the header isn't working, and I've attempted to display a new page, but again, they don't load. Anyone know where I'm going wrong?

<?php
$first = Rand(1,10);
$second = Rand(1,10);

echo <h1>"What is " . $first . "times " . $second . "?"</h1>;

if(is_int($_POST['answer']) == 1){
     if($_POST['first']*$_POST['second'] == $_POST['answer']){
        header("Location: correct.html");

        exit();  
    }
    else{
        header("Location: incorrect.html");

        exit();     
    }   
}
else if(is_string($_POST['answer']) == 1) {
    header("Location: response.html");

        exit();     
}

 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"          "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml">
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <title>Maths Quiz</title>
 </head>

 <body>
 <form method="POST" action="<?php echo $_SERVER['file:///X|/Software Development/PHP_SELF']; ?>">
 <p>Answer<br/>
 <input type="text" id="answer" name="answer" /></p>
 <p></p>
 <button type="submit" name="submit" value="send">Submit</button>
 <input type="hidden" name="answer" value="<?php echo $answer; ?>"/></p>
 </form>
 </body>
 </html>


您必须拥有标题()代码,特别是 echo 语句。

You must have the header() code before any output, especially that echo statement.