PHP While循环逻辑

时间:2014-07-04 15:40:09

标签: php jquery mysql forms post

你能救我吗?我正在尝试在我的系统中进行一些验证,但我对自己的想法感到困惑。

我创建了一个文本框,当您输入任何数字时它将循环播放。当文本框出现时,用户必须填写名称,但如果用户不小心输入了重复的名称,则会出现提示信息:"错误"。

我的系统中存在小错误,我想修复它。我认为有很多方法,但这最适合我的系统。

以下是代码:

<form action="fq1.php" method="post">    

    <input type="text" name="num" id="num">
    <input type="submit" value="select" name="select" id="select" />    

    <?php include 'conectthis.php';
        $num = $_POST['num'];

        if(isset($_POST['select']))
        {
            $x = 0;
            while($x <= $num)
            {
                $x++;
                echo "<input type='text' name='txt".$x."' />";
            }
            echo "<input type='submit' name='save' id='save' value='Save'>";
        }
        if(isset($_POST['save']))
        {
            $y = 0;
            while($y<=$num)
            {
                $y++;
                $mypost1 = "txt". $y;

                if($_POST[$mypost1] == $_POST[$mypost1])
                {
                    $prompts = "<script>alert('Names was not saved, please ensure that there are no duplicated Names');</script>";
                }
                else
                {
                    $runthis = "Update sampletable SET samplename = '$_POST[$mypost1]' WHERE id = '$y'";
                    mysql_query($runthis) or die(mysql_error());
                }
            }
            echo $prompts;
        }
    ?>
</form>

现在我的问题是if($_POST[$mypost1] == $_POST[$mypost1])文本框会识别它并显示提示信息,即使没有重复的名称。

这是我代码中的一个划痕,我想我知道这是正确的。 提前谢谢你,我是新手,还在学习。

0 个答案:

没有答案
相关问题