无法通过POST方法插入电子邮件

时间:2014-02-10 08:52:17

标签: php html5 post

我有通过POST方法从表单中获取数据的代码,但这里似乎存在某种问题。

以下是代码段。如果您发现任何问题,请帮助我。

获取错误:

some mandatory fields are empty and it is for the field email_address.
Undefined index: email_address in C:\wamp\www\test\employeee_insert.php

我的表单数据:

<tr>
   <td>email address:</td>
   <td><input type="email" name="email_address"></td>
</tr>

我的php文件数据:

if (empty($_POST["type"]) OR 
    empty($_POST["branch"]) OR 
    empty($_POST["name"]) OR      
    empty($_POST["address_1"]) OR 
    empty($_POST["state"]) OR 
    empty($_POST["city"]) OR 
    empty($_POST["pincode"]) OR 
    empty($_POST["mobile"]) OR 
    empty($_POST["email_address"]) OR  
    empty($_POST["password"])) 
{ 
    echo "some mendetory field(s) is/are empty. Please fill in the necessary details. ";
    mysqli_close($con); 
}

插入代码

$sql="INSERT INTO     employee_basic_info(employee_name,employee_type,branch,address_1,address_2,state,city,pincode,landline,mobile,email_address,password)
VALUES ('".$_POST['name']."','".$_POST['type']."','".$_POST['branch']."','".$_POST['address_1']."', '".$_POST['address_2']."','".$_POST['state']."','".$_POST['city']."','".$_POST['pincode']."','".$_POST['landline']."','".$_POST['mobile']."','".$_POST['email_address']."','".$_POST['password']."')";

1 个答案:

答案 0 :(得分:0)

您在电子邮件地址字段中输入错误。如果您获得文本类型,那么如果您不想更改电子邮件地址的类型,则应提交所有数据,然后输入有效的电子邮件地址,以便您的问题得以解决

   电子邮件地址:    

如果(isset($ _ POST [ '提交'])) {

if (empty($_POST["type"])||
    empty($_POST["branch"])|| 
    empty($_POST["name"]) ||      
    empty($_POST["address_1"])|| 
    empty($_POST["state"])||
    empty($_POST["city"]) || 
    empty($_POST["pincode"])||
    empty($_POST["mobile"]) || 
    empty($_POST["email_address"])||  
    empty($_POST["password"])) 
{ 
echo "some mendetory field(s) is/are empty. Please fill in the necessary details. ";
//mysqli_close($con); 
}
else
{
    echo $ins='insert into tbl_name(`type`,`branch`,`name`,`address_1`,`state`,`city`,`pincode`,`mobile`,`email_address`,`password`)values("'.$_POST["type"].'","'.$_POST["branch"].'","'.$_POST["name"].'","'.$_POST["address_1"].'","'.$_POST["state"].'","'.$_POST["city"].'","'.$_POST["pincode"].'","'.$_POST["mobile"].'","'.$_POST["email_address"].'","'.$_POST["type"].'")';
    mysql_query($ins);
}

}