我正在尝试验证输入到我正在使用PHP处理的表单提交中的数据,首先要确保填写字段,然后确保数据是正确的但出于某种原因无论我尝试做什么,数据都会被提交给数据库。
// example of validation (this is just duplicated for 4 fields)
if (isset($_POST["fullname"]) && !empty($_POST["fullname"])) {
header('Location: http://mywebsite.com/error');
} else {
// Trying to get it to redirect at all
header('Location: http://mywebsite.com/error');
}
$email = $_POST['email'];
// using google code email validation
include('EmailAddressValidator.php');
$validator = new EmailAddressValidator;
if ($validator->check_email_address($email)) {
// Email address is technically valid
} else {
header('Location: http://mywebsite.com/error');
}
// If this line is reached, submit the data to the DB but there's no way this line should be reached because the very first if & else statement should send it to the error page.
任何帮助将不胜感激!此时此刻已经尝试解决这个问题。
答案 0 :(得分:0)
尝试使用header.please重定向后添加exit;
,请参阅下面的示例:
header('Location: http://mywebsite.com/error');exit;
以下是您应如何提交表单的示例:
// example of validation (this is just duplicated for 4 fields)
if (isset($_POST["fullname"]) && isset($_POST["email"])) {
// using google code email validation
include('EmailAddressValidator.php');
$validator = new EmailAddressValidator;
$email = $_POST['email'];
if (empty($_POST["fullname"]) && !$validator->check_email_address($email)) {
header('Location: http://mywebsite.com/error');exit;
} else {
// enter into data here
}
}
答案 1 :(得分:-1)
首先制作第一个如果或不是AND ... if(isset($ _ POST [" fullname"])||!empty($ _ POST [" fullname"])) 第二,你必须说if($ validator-> check_email_address($ email)) //在DB中插入