首页  >  文章  >  后端开发  >  想做个简易php选择题答题系统

想做个简易php选择题答题系统

PHP中文网
PHP中文网原创
2017-03-21 14:25:233676浏览

问题:

想做个简易的答题系统,遇到点困难,就是提交不了,请大家帮帮忙,谢谢~!

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>问答</title>
</head>
 
<body>
<form name="t" mothod="post" action = "checktopic.php">
<form name="t1" mothod="post" action="">
1.6匹马拉着一架大车跑了6公里,6匹马一共跑了多少公里?<br />
<input type="radio" value="A"/>A.6  &nbsp
<input type="radio" value="B"/>B.16  <br />
<input type="radio" value="C"/>C.16  &nbsp
<input type="radio" value="D"/>D.36  <br />   
</form>
<br />
<form name="t2" mothod="post" action="">
2.兔子和乌龟比什么绝对不会输?<br />
<input type="radio" value="A"/>A.跳远  &nbsp
<input type="radio" value="B"/>B.跳高  <br />
<input type="radio" value="C"/>C.仰卧起坐  &nbsp
<input type="radio" value="D"/>D.赛跑  <br />
</form>
<br />
<form name="t3" mothod="post" action="">
3.小明妈妈:“小明赶紧切土豆去!”小明:“切,我不切!提问:小明要不要去切土豆?<br />
<input type="radio" value="A"/>A.切  &nbsp
<input type="radio" value="B"/>B.不切  <br />
<input type="radio" value="C"/>C.在犹豫  &nbsp
<input type="radio" value="D"/>D.不知道  <br />
</form>
<br />
<form name="t4" mothod="post" action="">
4.小明妈妈:“小明,去买瓶醋去!”小明:“我去,我不去!”提问:小明到底要不要去买醋?<br />
<input type="radio" value="A"/>A.去  &nbsp
<input type="radio" value="B"/>B.不去  <br />
<input type="radio" value="C"/>C.在犹豫  &nbsp
<input type="radio" value="D"/>D.妈妈去  <br />
</form>
<br />
<form name="t5" mothod="post" action="">
5.赛跑中,一名选手超过了第二名的选手,请问他现在是第几名<br />
<input type="radio" value="A"/>A.第一名  &nbsp
<input type="radio" value="B"/>B.第二名  <br />
<input type="radio" value="C"/>C.第三名  &nbsp
<input type="radio" value="D"/>D.第四名  <br />
</form>
<br />
<input type = "submit" value = "提交">
<input type = "reset" value = "重置">
</form>
</body>
</html>

验证页面

<?php
header(&#39;Content-type:text/html;charset = utf-8&#39;);
include_once (&#39;conn.php&#39;);
if($_POST[&#39;t1&#39;])
{
    $t = 0;
    $t1 = $_POST[&#39;t1&#39;];
    $t2 = $_POST[&#39;t2&#39;];
    $t3 = $_POST[&#39;t3&#39;];
    $t4 = $_POST[&#39;t4&#39;];
    $t5 = $_POST[&#39;t5&#39;];
    if($t1 == &#39;C&#39;)
    {
        $t += 20;
    }
    if($t2 == &#39;D&#39;)
    {
        $t += 20;
    }
    if($t3 == &#39;B&#39;)
    {
        $t += 20;
    }
    if($t4 == &#39;C&#39;)
    {
        $t += 20;
    }
    if($t5 == &#39;B&#39;)
    {
        $t += 20;
    }
}
$sql = "UPDATE `information`.`user` SET `sorce` = &#39;$t&#39; WHERE `user`.`username` = &#39;".$_COOKIE[&#39;user&#39;]."&#39;;";
mysql_query($sql);
$num = mysql_affected_rows();
if($num>0)
{
    echo "<script>alert(&#39;你的分数为:$t&#39;);location=&#39;index.php&#39;;</script>";
}
else
{
    echo "<script>alert(&#39;系统出错!&#39;);location=&#39;login.php&#39;;</script>";
}
?>

解决方法:

你的表单写错了

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>问答</title>
</head>
 
<body>
<form name="t" method="post" action = "checktopic.php">
 
1.6匹马拉着一架大车跑了6公里,6匹马一共跑了多少公里?<br />
<input type="radio" name="t1" value="A"/>A.6  &nbsp
<input type="radio" name="t1" value="B"/>B.16  <br />
<input type="radio" name="t1" value="C"/>C.16  &nbsp
<input type="radio" name="t1" value="D"/>D.36  <br />   
 
<br />
 
2.兔子和乌龟比什么绝对不会输?<br />
<input type="radio" name="t2" value="A"/>A.跳远  &nbsp
<input type="radio" name="t2" value="B"/>B.跳高  <br />
<input type="radio" name="t2" value="C"/>C.仰卧起坐  &nbsp
<input type="radio" name="t2" value="D"/>D.赛跑  <br />
 
<br />
 
3.小明妈妈:“小明赶紧切土豆去!”小明:“切,我不切!提问:小明要不要去切土豆?<br />
<input type="radio" name="t3" value="A"/>A.切  &nbsp
<input type="radio" name="t3" value="B"/>B.不切  <br />
<input type="radio" name="t3" value="C"/>C.在犹豫  &nbsp
<input type="radio" name="t3" value="D"/>D.不知道  <br />
 
<br />
 
4.小明妈妈:“小明,去买瓶醋去!”小明:“我去,我不去!”提问:小明到底要不要去买醋?<br />
<input type="radio" name="t4" value="A"/>A.去  &nbsp
<input type="radio" name="t4" value="B"/>B.不去  <br />
<input type="radio" name="t4" value="C"/>C.在犹豫  &nbsp
<input type="radio" name="t4" value="D"/>D.妈妈去  <br />
 
<br />
 
5.赛跑中,一名选手超过了第二名的选手,请问他现在是第几名<br />
<input type="radio" name="t5" value="A"/>A.第一名  &nbsp
<input type="radio" name="t5" value="B"/>B.第二名  <br />
<input type="radio" name="t5" value="C"/>C.第三名  &nbsp
<input type="radio" name="t5" value="D"/>D.第四名  <br />
 
<br />
<input type = "submit" value = "提交">
<input type = "reset" value = "重置">
</form>
</body>
</html>
<?php
header(&#39;Content-type:text/html;charset = utf-8&#39;);
include_once (&#39;conn.php&#39;);
 
    $t = 0;
    $t1 = $_POST[&#39;t1&#39;];
    $t2 = $_POST[&#39;t2&#39;];
    $t3 = $_POST[&#39;t3&#39;];
    $t4 = $_POST[&#39;t4&#39;];
    $t5 = $_POST[&#39;t5&#39;];
    if($t1 == &#39;C&#39;)
    {
        $t += 20;
    }
    if($t2 == &#39;D&#39;)
    {
        $t += 20;
    }
    if($t3 == &#39;B&#39;)
    {
        $t += 20;
    }
    if($t4 == &#39;C&#39;)
    {
        $t += 20;
    }
    if($t5 == &#39;B&#39;)
    {
        $t += 20;
    }
 
 
$sql = "UPDATE `information`.`user` SET `sorce` = &#39;$t&#39; WHERE `user`.`username` = &#39;".$_COOKIE[&#39;user&#39;]."&#39;;";
 
mysql_query($sql);
$num = mysql_affected_rows();
if($num>0)
{
    echo "<script>alert(&#39;你的分数为:$t&#39;);location=&#39;index.php&#39;;</script>";
}
else
{
    echo "<script>alert(&#39;系统出错!&#39;);location=&#39;login.php&#39;;</script>";
}
?>
声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn