简体   繁体   English

报名表上的“错误”

[英]Php “errors” on registration form

Hey guys I'm having a bit of a problem not getting my errors to show on my form. 大家好,我在将错误显示在表单上时遇到了一些问题。 This is the code Im running live (just testing it on my hosting site) and it's not showing anything when I put things into the test field. 这是Im实时运行的代码(仅在托管站点上对其进行测试),当我将其放入测试字段时,它什么也不显示。 Any idea as to what might be wrong? 关于什么可能是错的任何想法?

<?php

    if ($_POST['submit']) {

      if (!$_POST['email']) $error.="Please enter your email!";
        else if !(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) $error.="Uh Uh uh, you didn't enter a valid email address!";

    if (!$_POST['password']) $error.="Please enter a password!";
        else {

         if (strlen($_POST['password'])<8) $error.="Please enter a password of at least 8 characters.";
        if (!preg_match('`[A-Z]`',$_POST['password'])) $error.="Please include at least one capital letter in your password."

        }

    if ($error) echo "There were error(s) in your sign up details:".$error;
    }


?>


<form method="post">

    <input type ="email" name="email" id="email" />

    <input type ="password" name="password" />

    <input type ="submit" name="submit" value ="Click for Cookies" />

</form>

I'm going to echo what @Casmir said in the comments about using isset, but have you tried submitting something incorrect and then simply viewed the page source? 我将回应@Casmir在有关使用isset的评论中所说的内容,但是您是否尝试提交不正确的内容,然后只是查看页面源代码? When you do, is the text there? 当您这样做时,文本在那里吗?

If it isn't then your test conditionals and possible the conditional looking for an error are incorrect, try using isset on the $error variable as well. 如果不是,则您的测试条件以及可能的条件查找错误均不正确,请尝试在$ error变量上使用isset。

One more thing, you said this is on a hosting site, make sure you have display_error set to On via a local php.ini file (or however your hoster supports custom PHP config values) to make sure there aren't code errors preventing the execution from completing either which would be hidden via 'production level' settings (Also remove them when finished testing of course!). 还有一件事情,您说这是在托管站点上,请确保通过本地php.ini文件将display_error设置为On(或者托管人支持自定义PHP配置值),以确保没有代码错误来阻止可以通过“生产级别”设置隐藏其中的任何一个来执行(当然,在完成测试后也要删除它们!)。

您的条件不正确,因为您正在检查!$ _ POST [email] ,因为每当您需要检查is_empty($ _ POST [email])时 ,您都会得到它,如果是,则可以回显“不允许为空”或其他内容(如果不为空),则可以放置正则表达式来检查有效的电子邮件ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM