日期:2014-05-17  浏览次数:20488 次

求大神看看这个关于创建问题的代码
PHP code

<?php
error_reporting(E_ALL & ~ E_NOTICE);
echo "<center>";
if (!$_POST["question_num"])
{
    echo "<h2>create question</h2>";
    echo "<table border=1>";
    echo "<form method=post action=".$_SERVER["PHP_SELF"].">";
    echo "<tr>";
    echo "<td>create those questions is belong to</td>";
    echo "<td>";
    echo "<select size=1 name=f>";
    include 'config.php';

    $sql="select `id`,`content` from question where f=0";
    $result=mysql_query($sql);
    while ($row=mysql_fetch_array($result))
    {
        echo "<option value=".$row["id"];
        echo ">".$row[content];
        echo "</option>";
    }
    echo "</select>";
    echo "</td>";
    echo "</tr>";
    echo "<tr>";
    echo "<td>how many question will you want to create</td>";
    echo "<td><input type=text name=question_num size=5></td>";
    echo "</tr>";
    echo "</tr>";
    echo "<tr>";
    echo "<td colspan=2><center><input type=submit value=next></center></td>";
    echo "</tr>";
    echo "</form>";
    echo "</table>";
    echo "fuck";
}
else if (!$_POST["question_num"])
{
    echo "<h2>create question</h2>";
    echo "<table border=1>";
    echo "<form method=post action=".$_SERVER["PHP_SELF"].">";
    $num=$_POST["question_num"];
    echo "<input type=hidden name=question_num value=".$num.">";
    echo "<input type=hidden name=f value=".$_POST["f"].">";
    echo "<tr>";
    echo "<td>content</td>";
    echo "<td>result</td>";
    echo "</tr>";
    for ($i=0;$i<$num;$i++)
    {
        echo "<tr>";
        echo "<td>question".($i+1).":<input type=text name=question[] size=40></td>";
        echo "<td>";
        echo "<select size=1 name=to[]>";
        echo "<option value=0>no<option>";
        echo "<option value=1>yes<option>";
        echo "</select>";
        echo "</td>";
        echo "</tr>";
    }
    echo "<tr>";
    echo "<td><center><input type=submit value=submit></center></td>";
    echo "</tr>";
    echo "</form>";
    echo "</table>";
}
else
{
    $num=$_POST["question_num"];
    $f=$_POST["f"];
    $sql="insert into question(`f`,`t`,`content`)values";
    for ($i=0;$i<$num;$i++)
    {
        $content=$_POST["question"][$i];
        $t=$_POST["to"][$i];
        $sql=$sql."('".$f."','".$t."','".$content."')";
        if ($i<$num-1)
        $sql=$sql.",";
    }
    include 'config.php';
    $re=mysql_query($sql);
    if ($re)
    {
        echo "create question successful!";
        echo "<p>";
        echo "click<a href=add_answer.php>here</a>to add answer";
    }
}
echo "<center>";
?>


数据库方面没有问题,就是我输入问题个数点击下一步的时候,就直接转到下一个添加答案的页面去了...本来应该实现的是,查询question,如果有问题数量没有问题内容时候,进入else if那里面,执行循环创建问题...为什么