此代码给我500内部服务器错误

时间:2019-06-16 11:10:58

标签: php

我正在为我的网站制作注册系统,但是此脚本给我内部服务器500错误。该文件验证注册表单中的输入,然后处理信息验证它并注册用户

我尝试了E_all,但仅在此内部500上没有出现错误

<?php 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// error_reporting(E_ALL);
require_once("includes/functions.inc");

// prevent if form is not submited

if (!isset($_POST['submit']))
{
    die(header("Location: register.php"));
}

$_SESSION['formAttempt'] = true;
if (isset($_SESSION['error'])) 
{
    unset($_SESSION['error']);
}

// array for error

$_SESSION['error']= array();
$required = array("lname","fname","email","password1","password2");


// check required feilds
foreach ($required as $requiredFields) {
    if (!isset($_POST[$requiredField]) || $_POST[$requiredField]
   == " ") {
        $_SESSION['error'][] = $requiredField . " is required.";
    }
}
// for validation of firstname lastname and others
if (!preg_match('/^[\w .]+$/', $_POST['fname'])) {
    $_SESSION['error'][] = "First name must letters and numbers only";
}

if (!preg_match('/^[\w .]+$/', $_POST['lname'])) {
    $_SESSION['error'][] = "Last name must letters and numbers only";
}

if (!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)) 
{
    $_SESSION['error'] [] = "Invalid Email";
}

if ($_POST['password1'] != $_POST['password2']) 
{
    $_SESSION['error'] [] = "Passwords do not match!";
}

// final disposation
if (count($_SESSION['error']) > 0) 
{
    die(header("Location : register.php"));
} else {
    if (registerUser($_POST)) {
        unset($_SESSION['formAttempt']);
        die(header("Location: success.php"));

    } else {
        error_log("Problem registering user: {$_POST['email']}");
        $_SESSION['error'] [] = "Problem registering account";
        die(header("Location: register.php"));

    }
}

function registerUser($userData)
{
    $mysqli = new MYSQLI(DBHOST,DBUSER,DBPASS,DB);
    if ($mysqli->connect_errno) {

        error_log("Cannot Connect to server" . $mysqli->connect_errno);
        return false;

    }
    $email = $mysqli->real_escape_string($_POST['email']);
    // CCHEK IF USER EXIST

    $findUser = "SELECT id from Customer WHERE email = '{$email}'";
    $findResult = $mysqli->query($findUser);
    $findRow = $findResult->fetch_asssoc();

    if (isset($findRow['id']) && $findRow['id'] != "") {
     $_SESSION['error'][] = "A user with that e-mail
address already exists";
     return false;
    }
         $lastName = $mysqli->real_escape_string($_POST['lname']);
 $firstName = $mysqli->real_escape_string($_POST['fname']);

  $cryptedPassword = crypt($_POST['password1']);
 $password = $mysqli->real_escape_string($cryptedPassword);


$query = "INSERT INTO Customer (email,create_date,password,last_name,first_name)". "  VALUES('{$email}', NOW() , '{$password}' , '{$lastName}', '{$firstName}')";
if ($mysqli->query($query)) {
    $id = $mysqli->insert_id;
    error_log("Inserted {$email} as ID {$id}");
    return true;

} else {
    error_log("Problem inserting {$query}");
    return flase;

}

}
// registerUser end
?>

它应该验证表单并在数据库中输入

0 个答案:

没有答案