php页面空白

时间:2015-06-06 01:53:30

标签: php mysql database insert-query

我提交表单时页面变为空白。提交按钮位于表单标签中,所有表单标签都已就位。

     <?php

error_reporting(-1);

ini_set('display_errors', 'On');

try{
    DEFINE("server_name", "localhost");
    DEFINE("user_name", "ricxxstr_haris");
    DEFINE("password", "Haris900");
    DEFINE("db_name", "ricxxstr_pantry");

    // Create connection

    $conn=@mysqli_connect("localhost","ricxxstr_haris","Haris900","ricxxstr_pantry");

echo 'asd';

// Check connection

if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);
} 
 echo 'asd';

if($_SERVER['REQUEST_METHOD']=='POST'){


 $firstname = $_POST['first_name'];

 $lastname = $_POST['last_name'];

 $age = $_POST['DOB'];

 $email = $_POST['email'];

 $telephone = $_POST['telephone'];

 $Street_Address = $_POST['Street_Address'];

 $City = $_POST['City'];

 $ZIP = $_POST['ZIP'];

 $State = $_POST['a'];

 $Ethnicity = $_POST['b'];

 $HH = $_POST['HH'];

 $HH1 = $_POST['HH1'];

 $HH2 = $_POST['HH2'];

 $HH3 = $_POST['HH3'];

 $HH4 = $_POST['HH4'];


$sql = "INSERT INTO `Visitors`

                (

                    `first_name`,
                    `last_name`,
                    `Email_address`,
                    `Phone_no`,
                    `St_Addr`,
                    `city`,
                    `State`,
                    `zip`,
                    `age`,
                    `Ethnicity`,
                    `HH`,
                    `Signup_date`

                ) VALUES (

                    '$firstname',
                    '$lastname',
                    '$email',
                    $telephone,
                    '$Street_Address',
                    '$City',
                    '$State',
                    $ZIP,
                    $age,
                    '$Ethnicity',
                    $HH,
                    CURRENT_TIMESTAMP
                    )";


if (mysqli_query($conn, $sql)) {


$sql1 = "INSERT INTO `houseHold`(`Cust_id`,  `0-18`, `19-54`, `55-64`, `+65`) VALUES ((SELECT `Cust_id` FROM `Visitors` WHERE `first_name`='$firstname' and `last_name` = '$lastname' and `Email_address` = '$email'), $HH1, $HH2, $HH3, $HH4)";

echo $sql1;

    if (mysqli_query($conn, $sql1)) {

       $Message = urlencode("Info Entered Sucessfully!");

    header("Location:http://ilovetherefuge.org/?page_id=2113&Message=".$Message);

    echo 'asd';

    die;

       }else {

    echo "Error2: " . $sql1 . "<br>" . mysqli_error($conn);

    }

 else {

    echo "Error1: " . $sql . "<br>" . mysqli_error($conn);
}

}
mysqli_close($conn);

}catch(Exception $e){

    $e->getMessage();

}

?>

在我输入第二个查询之前,代码运行良好。 Header也适用于单一查询。我想添加客户的数据然后使用相同的php我想在其他表中添加客户ID的数据。

1 个答案:

答案 0 :(得分:0)

第一次出现下一句时尝试删除:

echo 'asd'

你在'header'函数之前发送信息,这是不允许的:

http://php.net/manual/en/function.header.php