PHP表单验证不继续

时间:2016-10-25 19:51:26

标签: php sql validation wamp

我在表单上进行了以下验证,该表单在wamp上完美运行,并使用标头中的变量重定向到正确的页面。但是当我在实时网站上部署时,一旦我点击按钮,它就会重新加载页面,只有标题可见。

require_once "config/dbconnect.php";
require_once "header.php";

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$courseid = $_GET['courseid'];

$error = false;


if (isset($_POST['register'])) {
$validated = true;
    $email = trim($_POST['email']);
    $password1 = $_POST['password1'];
    $password2 = $_POST['password2'];
    $firstname = trim($_POST['firstname']);
    $lastname = trim($_POST['lastname']);

    $address = trim($_POST['address']);
    $postcode = trim($_POST['postcode']);
    $phonenumber = trim($_POST['phonenumber']);

    if(!filter_var($email,FILTER_VALIDATE_EMAIL))
    {
            $error = true;
            $email_error = "<font color='red'>Please enter a valid email address</font>";
    }
    // else
    //  $stmt = $db->prepare('SELECT email FROM users WHERE email = :email');
    //  $stmt->execute(array(':email' => $_POST['email']));
    //  $row = $stmt->fetch(PDO::FETCH_ASSOC);

    if(!empty($row['email'])){
            $error = true;
            $emailinuse= "<font color='red'>Email address is already in use, choose another</font>";
        }
    if(empty($password1))
    {
            $error = true;
            $password1_error = "<font color='red'>Please enter a password</font>";
    }
    if(empty($password2))
    {
            $error = true;
            $password2_error = "<font color='red'>Please verify your password</font>";
    }
    if($_POST['password1'] != $_POST['password2']) {
        $error = true;
        $passworderror = "<font color='red'>Passwords do not match</font>";
    }
    if (!preg_match("/^[a-zA-Z ]+$/",$firstname))
    {
            $error = true;
            $firstname_error = "<font color='red'>First name cannot contain invalid characters</font>";
    }
    if (!preg_match("/^[a-zA-Z ]+$/",$lastname))
    {
            $error = true;
            $lastname_error = "<font color='red'>Last name cannot contain invalid characters</font>";
    }
    if(empty($address))
    {
            $error = true;
            $address_error = "<font color='red'>Please enter your address</font>";
    }
    if(empty($postcode))
    {
            $error = true;
            $postcode_error = "<font color='red'>Please enter your postcode</font>";
    }
if(empty($phonenumber))
{
    $error = true;
    $phoneno_error = "<font color='red'>Please enter your phonenumber</font>";
  }
if (!$error) {
  $bindValues = [
        ':email' => isset($_POST['email']) && trim($_POST['email']) != false ? $_POST['email'] : null,
        ':firstname' => isset($_POST['firstname']) && trim($_POST['firstname']) != false ? $_POST['firstname'] : null,
        ':lastname' => isset($_POST['lastname']) && trim($_POST['lastname']) != false ? $_POST['lastname'] : null,
        ':password' => password_hash(isset($_POST['password1']) && trim($_POST['password1']) != false ? $_POST['password1'] : '', PASSWORD_BCRYPT),
        ':address' => isset($_POST['address']) && trim($_POST['address']) != false ? $_POST['address'] : null,
        ':postcode' => isset($_POST['postcode']) && trim($_POST['postcode']) != false ? $_POST['postcode'] : null,
        ':phonenumber' => isset($_POST['phonenumber']) ? $_POST['phonenumber'] : null,
        ':usertype' => "Registered"
];
$stmt = $db->prepare('INSERT INTO users (email, firstname, lastname, password, address, postcode, phonenumber, usertype) VALUES (:email, :firstname, :lastname, :password, :address, :postcode, :phonenumber, :usertype)');
$stmt->execute($bindValues);
$userid = $db->lastInsertId();
header( "Location: payment.php?courseid=$courseid&uid=$userid" );
}
}

在wamp或live site上看不到任何错误

0 个答案:

没有答案