>  기사  >  백엔드 개발  >  想做个简易php选择题答题系统

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

PHP中文网
PHP中文网원래의
2017-03-21 14:25:233677검색

问题:

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

<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으로 문의하세요.
이전 기사:md5다음 기사:搜索分页关键字值无法传送