由于发生内部服务器错误,无法显示页面 - PHP

时间:2015-07-23 06:31:48

标签: php html forms

我有一个php脚本文件,它从表单中获取信息并将其放入sql数据库,脚本完成后我强制将浏览器重定向到另一个网页。

在本地运行此脚本时,它可以正常运行..将信息放入数据库并重定向到aboutus.html。但是在我的服务器上,它也通过输入信息并将其插入数据库来完成应该做的事情,但是不是重定向浏览器,而是显示一个带有以下单词的纯白页:

The page cannot be displayed because an internal server error has occurred.

没有错误编号;没有。我有一个

error_reporting(E_ALL);

报告任何错误,但没有指明它是什么。通过遵循我的代码并感觉数据被物理地放入数据库中,它显然会在没有任何错误的情况下运行该部分代码,但是一旦它遇到代码部分以重定向浏览器,它就会失败。这是我的代码部分到说明。

if(""!=trim($_POST["spFirstName"])){
    $host = //taken out for security reasons;
    $user = //taken out for security reasons;
    $pass = //taken out for security reasons;
    $db = //taken out for security reasons;
    //connect to database
    $con = mysqli_connect($host, $user, $pass, $db);      //connects to database

    if (!$con){    
        die("Connection failed: " .my_sqli_connect_err());
    }

    //Spirit Vars - reformats data from previous form

    $firstName =  ucwords(strtolower($_POST["spFirstName"]));
    $firstName = mysqli_real_escape_string($con, $firstName);

    $lastName =  ucwords(strtolower($_POST["spLastName"]));
    $lastName = mysqli_real_escape_string($con, $lastName);

    $email =  $_POST["spEmail"];
    $email = mysqli_real_escape_string($con, $email);

    $spComment =  htmlspecialchars($_POST['spComment']);
    $spComment = mysqli_real_escape_string($con, $spComment);


    $findEmail = "SELECT * FROM notAttending WHERE email='" . $email."'";
    $results = mysqli_query($con, $findEmail);
    if(mysqli_num_rows($results) > 0){
        echo "Looks like you have already let us know that you won't be attending! Thanks for being with us in spirit! Any questions please email us at duanannari@gmail.com :)";
    }
    else{
        //create SQL statement to create new row;
        $sql = "INSERT INTO notAttending (spFirstName, spLastName, spEmail, spComment) VALUES ('".$firstName."', '".$lastName."',  '".$email."',  '".$spComment."');";


        // This is where I believe the code doesn't work?? Maybe??

        if (mysqli_query($con, $sql)){
            header("Location: http://www.uyswedding.com/aboutus.html");
        }
        else{
           echo "Error: " . $sql . "<br>" . mysqli_error($con);
        }
    }

}

现在为了增加一点混乱,我实际上在同一个脚本文件(.php)中有相同的代码,根据用户是否输入了某些字段来处理不同的数据。

此表单用于婚礼,因此用户可以rsvp或“不参加”,具体取决于用户使用此脚本文件的路径将数据导向数据库中的正确表格。

所以如果有人'rsvps'并且点击进入。数据被放入数据库并重定向到网页..但是,如果有人填写“不参加”,它会给我这个错误。

话虽如此.3个月前我对这个剧本没有任何问题,从那以后我没有故意做过任何改动。从那时起,该网站一直处于不确定状态。我将在所有这些文本下添加整个php文件,以便上面的描述更有意义。谢谢!

<?php
error_reporting(E_ALL);

if(""!=trim($_POST["FirstName"])){
    $host = //taken out for security reasons;
    $user = //taken out for security reasons;
    $pass = //taken out for security reasons;
    $db = //taken out for security reasons;

    //connect to database
    $con = mysqli_connect($host, $user, $pass, $db);

if (!$con){
    die("Connection failed: " .my_sqli_connect_err());
}

//Spirit Vars
$firstName =  ucwords(strtolower($_POST["FirstName"]));
$firstName = mysqli_real_escape_string($con, $firstName);

//Person Vars
$firstName =  ucwords(strtolower($_POST["FirstName"]));
$firstName = mysqli_real_escape_string($con, $firstName);

$lastName =   ucwords(strtolower($_POST["LastName"]));
$lastName = mysqli_real_escape_string($con, $lastName);


$guestFirst = ucwords(strtolower($_POST["guestFirst"]));
$guestFirst = mysqli_real_escape_string($con, $guestFirst);


$guestLast =   ucwords(strtolower($_POST["guestLast"]));
$guestLast = mysqli_real_escape_string($con, $guestLast);

/**************************FIRST CHILD ***********/
$childFirst_one = ucwords(strtolower($_POST["childFirst_one"]));
$childFirst_one = mysqli_real_escape_string($con, $childFirst_one);

$childLast_one =   ucwords(strtolower($_POST["childLast_one"]));
$childLast_one = mysqli_real_escape_string($con, $childLast_one);

$childAge_one =   ucwords(strtolower($_POST["childAge_one"]));
$childAge_one = mysqli_real_escape_string($con, $childAge_one);

/**************************SECOND CHILD ***********/
$childFirst_two = ucwords(strtolower($_POST["childFirst_two"]));
$childFirst_two = mysqli_real_escape_string($con, $childFirst_two);

$childLast_two =   ucwords(strtolower($_POST["childLast_two"]));
$childLast_two = mysqli_real_escape_string($con, $childLast_two);

$childAge_two =   ucwords(strtolower($_POST["childAge_two"]));
$childAge_two = mysqli_real_escape_string($con, $childAge_two);

/**************************THIRD CHILD ***********/
$childFirst_three = ucwords(strtolower($_POST["childFirst_three"]));
$childFirst_three = mysqli_real_escape_string($con, $childFirst_three);

$childLast_three =   ucwords(strtolower($_POST["childLast_three"]));
$childLast_three = mysqli_real_escape_string($con, $childLast_three);

$childAge_three =   ucwords(strtolower($_POST["childAge_three"]));
$childAge_three = mysqli_real_escape_string($con, $childAge_three);

/**************************THIRD CHILD ***********/
$childFirst_four = ucwords(strtolower($_POST["childFirst_four"]));
$childFirst_four = mysqli_real_escape_string($con, $childFirst_four);

$childLast_four =   ucwords(strtolower($_POST["childLast_four"]));
$childLast_four = mysqli_real_escape_string($con, $childLast_four);

$childAge_four =   ucwords(strtolower($_POST["childAge_four"]));
$childAge_four = mysqli_real_escape_string($con, $childAge_four);


$email =  $_POST["email"];
$email = mysqli_real_escape_string($con, $email);


$songRequest = $_POST["songRequest"];
$songRequest = mysqli_real_escape_string($con, $songRequest);


//see if record exists
$findEmail = "SELECT * FROM inPerson WHERE email='" . $email."'";
$results = mysqli_query($con, $findEmail);
if(mysqli_num_rows($results) > 0){
    echo "Oops! Looks like you already RSVP'd. Any questions please email us at duanannari@gmail.com :)";
}
else{
    //create SQL statement to create new row;
    $sql = "INSERT INTO inPerson (firstName, lastName, guestFirst, guestLast, childFirst_one, childLast_one, childAge_one, childFirst_two, childLast_two, childAge_two, childFirst_three, childLast_three, childAge_three, childFirst_four, childLast_four, childAge_four, email, songRequest) VALUES ('".$firstName."', '".$lastName."', '".$guestFirst."', '".$guestLast."', '".$childFirst_one."', '".$childLast_one."', '".$childAge_one."', '".$childFirst_two."', '".$childLast_two."', '".$childAge_two."', '".$childFirst_three."', '".$childLast_three."', '".$childAge_three."', '".$childFirst_four."', '".$childLast_four."', '".$childAge_four."', '".$email."', '".$songRequest."');";

    if (mysqli_query($con, $sql)){
        header("Location: http://www.uyswedding.com/bloemfontein.html");
    }
    else{
        echo "Error: " . $sql . "<br>" . mysqli_error($con);
    }
}

}
else{
if(""!=trim($_POST["spFirstName"])){
    $host = //taken out for security reasons;
    $user = //taken out for security reasons;
    $pass = //taken out for security reasons;
    $db = //taken out for security reasons;
    //connect to database
    $con = mysqli_connect($host, $user, $pass, $db);

    if (!$con){
        die("Connection failed: " .my_sqli_connect_err());
    }

    //Spirit Vars
    $firstName =  ucwords(strtolower($_POST["spFirstName"]));
    $firstName = mysqli_real_escape_string($con, $firstName);

    $lastName =  ucwords(strtolower($_POST["spLastName"]));
    $lastName = mysqli_real_escape_string($con, $lastName);

    $email =  $_POST["spEmail"];
    $email = mysqli_real_escape_string($con, $email);

    $spComment =  htmlspecialchars($_POST['spComment']);
    $spComment = mysqli_real_escape_string($con, $spComment);


    $findEmail = "SELECT * FROM notAttending WHERE email='" . $email."'";
    $results = mysqli_query($con, $findEmail);                            //137
    if(mysqli_num_rows($results) > 0){                         
        echo "Looks like you have already let us know that you won't be attending! Thanks for being with us in spirit! Any questions please email us at duanannari@gmail.com :)";
    }
    else{
        //create SQL statement to create new row;
        $sql = "INSERT INTO notAttending (spFirstName, spLastName, spEmail, spComment) VALUES ('".$firstName."', '".$lastName."',  '".$email."',  '".$spComment."');";

        if (mysqli_query($con, $sql)){
            header("Location: http://www.uyswedding.com/aboutus.html");
        }
        else{
           echo "Error: " . $sql . "<br>" . mysqli_error($con);
        }
    }

}

}     ?&GT;

0 个答案:

没有答案