dsgwdigu84950 2015-07-19 16:07
浏览 28
已采纳

注册验证,同一页面上显示错误消息

I am currently creating a registration page and checking for errors. I have the errors working correctly but when I report them, they end up on a new page. I was wondering how I get it to not redirect to a different page?

I echo out a div that I was thinking would appear next to the form but that is not occuring. Here is my form and error validation:

<form action="signup.php" method="post">
                <input type="text" name="First_name" placeholder="First Name" />
                <input type="text" name="Last_name" placeholder="Last Name" />
                <input type="text" name="Email" placeholder="Email Address" />
                <input type="text" name="Email2" placeholder="Comfirm Email Address" />
                <input type="password" name="Password" placeholder="Password" />
                <input type="submit" value="Submit" name="submit"/>
</form>

This is part of my php file.

if (isset($_POST['submit'])) {
$error = array();
$firstname=$_POST['First_name'];
$lastname=$_POST['Last_name'];
$email=$_POST['Email'];
$email2=$_POST['Email2'];
$password=$_POST['Password'];

if (strlen($password) <= 6 and strlen($password) >= 1) {
    if (strlen($password) >= 20) {
        if (strlen($email) >= 1 and strlen($email) <= 55) {
            if ($email == $email2) {
                if (ereg('^[a-zA-Z0-9\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $email)) {
                        $sql = "INSERT INTO Users (First_Name, Last_Name, Email, Password) VALUES ('$firstname','$lastname','$email','$password')";
                            echo "Regiration Complete. Check Email for Validation.";
                            exit;
                    } else {
                        $error[] = 'Email is wrong';
                    }
                } else {
                    $error[] = 'Email addresses are not the same';
                }
            } else {
                $error[] = 'Email Address is too long';
            }
        } else {
            $error[] = 'Password is too long';
        }
    } else {
        $error[] = 'Password must be 6 Characters';
    }
}
echo '<div class="errormsgbox"> <ol>';
    foreach ($error as $key => $values) {
        echo '  <li>'.$values.'</li>';
    }
echo '</ol></div>';
  • 写回答

3条回答 默认 最新

  • dongyi1441 2015-07-19 16:38
    关注

    You can use HTML5 to validate these Data without PHP - so the form doesn't even get sent if its violating your standards.

    You can read more about it here:

    http://www.the-art-of-web.com/html/html5-form-validation/

    To your question:

    You load a different page. This means, that you have to include the form there, too, if you want to get it shown there. Otherwise it won't display.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 Mac系统vs code使用phpstudy如何配置debug来调试php
  • ¥15 目前主流的音乐软件,像网易云音乐,QQ音乐他们的前端和后台部分是用的什么技术实现的?求解!
  • ¥60 pb数据库修改与连接
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)