<?php
require 'config.php';
if(!empty ($_POST)){
$nameError = null;
$emailError = null;
$mobileError = null;
$addressError = null;
$name = $_POST['name'];
$email_address = $_POST['email_address'];
$mobile_no = $_POST['mobile_no'];
$address = $_POST['address'];
$valid = true;
if(empty($name)){
$nameError = 'Provide Name.'
$valid = false;
}
if(empty($email_address)){
$emailError = 'Provide Email Address.'
$valid = false;
}else if(!filter_var($email_address, FILTER_VALIDATE_EMAIL)){
$emailError = 'Provide a valid Email Address.'
$valid = false;
}
if(empty($mobile_no)){
$mobileError = 'Provide Mobile Number.'
$valid = false;
}
if(empty($address)){
$addressError = 'Provide Address.'
$valid = false;
}
if($valid){
$connection=Database::connect();
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query="INSERT INTO Customers(name,email_address,mobile_no,address) values(?,?,?,?)";
$exe_query->$connection->prepare($query);
$exe_query->execute(array,($name,$email_address,$mobile_no,$address));
Database::disconnect();
}
}
?>
答案 0 :(得分:0)
在大多数陈述
中缺失$ nameError =&#39;提供姓名。&#39; $ emailError =&#39;提供有效的电子邮件地址。&#39;
以及更多,检查
答案 1 :(得分:0)
有很多selicolum
错误和execute
人为错误
正确的方法
<?php
require 'config.php';
if(!empty ($_POST)){
$nameError = null;
$emailError = null;
$mobileError = null;
$addressError = null;
$name = $_POST['name'];
$email_address = $_POST['email_address'];
$mobile_no = $_POST['mobile_no'];
$address = $_POST['address'];
$valid = true;
if(empty($name)){
$nameError = 'Provide Name.';// missing selicolum
$valid = false;
}
if(empty($email_address)){
$emailError = 'Provide Email Address.';// missing selicolum
$valid = false;
}else if(!filter_var($email_address, FILTER_VALIDATE_EMAIL)){
$emailError = 'Provide a valid Email Address.';
$valid = false;
}
if(empty($mobile_no)){
$mobileError = 'Provide Mobile Number.';// missing selicolum
$valid = false;
}
if(empty($address)){
$addressError = 'Provide Address.';// missing selicolum
$valid = false;
}
if($valid){
$connection=Database::connect();
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query="INSERT INTO Customers(name,email_address,mobile_no,address) values(?,?,?,?)";
$exe_query->$connection->prepare($query);
$exe_query->execute(array($name,$email_address,$mobile_no,$address));// execute command mistake
Database::disconnect();
}
}
?>