<table border="0" cellpadding="0" cellspacing="0">
<form method="post" action="#">
<tr>
     <td height="25">输入Email:</td>
        <td height="25"><input name="email" type="text" /></td>
        <td><input type="submit" value="检测" /></td>
    </tr>
</form>
</table>
<?php
if(isset($_post['']));
$email = $_POST['email'];
if(trim($email) != ''){
$pattern = '/^[a-zA-Z][a-zA-z0-9-]*[@]([a-zA-Z0-9]*[.]){1,3}[a-zA-Z]*/';
if(preg_match($pattern,$email) == 1){
echo '输入格式正确: '.$email;
}else{
echo '输入格式错误!!';
}
}
?>运行以上代码的时候,出现以下提示
Notice: Undefined index: email in C:\wamp\www\1.php on line 12
请问如何改?

解决方案 »

  1.   

    感觉代码有很多不规范呀!你看看下面我修改的代码(不好请见谅)<table border="0" cellpadding="0" cellspacing="0">
    <form method="post" action="#">
    <tr>
         <td height="25">输入Email:</td>
            <td height="25"><input name="email" type="text" /></td>
            <td><input type="submit" value="检测" /></td>
        </tr>
    </form>
    </table>
    <?php
    if(isset($_POST['email'])) {
    $email = $_POST['email'];
    if(trim($email) != ''){
    $pattern = '/^[a-zA-Z][a-zA-z0-9-]*[@]([a-zA-Z0-9]*[.]){1,3}[a-zA-Z]*/';
    if(preg_match($pattern,$email) == 1){
    echo '输入格式正确: '.$email;
    }else{
    echo '输入格式错误!!';
    }
    }
    }
    ?>
      

  2.   

    if($_POST) {
      $email = $_POST['email'];
      if(trim($email) != ''){
        $pattern = '/^[a-zA-Z][a-zA-z0-9-]*[@]([a-zA-Z0-9]*[.]){1,3}[a-zA-Z]*/';
        if(preg_match($pattern,$email) == 1){
          echo '输入格式正确: '.$email;
        }else{
          echo '输入格式错误!!';
        }
      }
    }