PHP - 显示未定义的索引通知

时间:2016-01-12 17:13:16

标签: php html

<?php

if($_POST['submit']=="Sign Up") {

    if(!$_POST['email']) $error.="<br />Please enter your email";
        else if (!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) $error.="<br />Please enter a valid email adress";

    if(!$_POST['password']) $error.="<br />Please enter your password";
        else {

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

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

}

?>
    <form method="post">
        <input type="email" name="e-mail" id="email"/>
        <input type="password" name="password"/>
        <input type="submit" name="submit" value="Sign Up"/>
    </form>

我收到以下行的未定义索引通知:

if($ _ POST [&#39; submit&#39;] ==&#34;注册&#34;){

这种通知的含义是什么?如何让它消失?

1 个答案:

答案 0 :(得分:0)

您必须使用isset()

<?php
$value = @$_POST['submit']; 
if(isset($_POST['submit']))//watch here when u  trigger submit button it will find out
if($_POST['submit']=="Sign Up") {

    if(!$_POST['e-mail']) // and here too u have to use e-mail because in ur html code type of input emil name is e-mail
      $error.="<br />Please enter your email";
     else if (!filter_var($_POST['e-mail'], FILTER_VALIDATE_EMAIL)) $error.="<br />Please enter a valid email adress";

    if(!$_POST['password']) $error.="<br />Please enter your password";
        else {

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

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

}

?>
    <form method="post">
        <input type="email" name="e-mail" id="email"/>
        <input type="password" name="password"/>
        <input type="submit" name="submit" value="Sign Up"/>
    </form>