2015-06-06 163 views
1

當我提交表單時頁面變爲空白。提交按鈕位於表單標籤中,所有表單標籤均已就位。php頁面變爲空白

 <?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 

    [email protected]_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(); 

} 

?> 

在我輸入第二個查詢之前,代碼運行良好。標題也適用於單個查詢。我想添加客戶的數據,然後使用相同的PHP我想添加數據與其他表中的客戶ID。

+0

回聲「ASD 「;刪除,但不能改變 –

+0

@johnConde我找不到它,請指導我。 –

+0

打開錯誤報告 –

回答

0

嘗試刪除第一次出現的下一句話:

echo 'asd' 

You're的 '頭' 功能之前,發送信息,這是不允許的:

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

+0

這只是檢查多少代碼工作 –

+0

仍然是一樣的 –

+0

我想是這樣,但然後標題不起作用,並且頁面變爲空白 – etrull