2016-01-30 42 views
1
<?php 
session_start(); 
include 'dbConnection.php'; 
?> 
<!DOCTYPE HTML> 
<html> 
<head> 
    <title>Online Book Club</title> 

</head> 

<body> 
    <form method ="post" action ="register.php"> 

      <?php 
     //get the values from the form, using the POST method. 
     $first_name = $_POST['first_name']; 
     $last_name = $_POST['last_name']; 
     $profession = $_POST['profession']; 
     $gender = $_POST['gender']; 
     $date_of_birth = $_POST['date_of_birth']; 
     $country_of_residence = $_POST['country_of_residence']; 
     $email = $_POST['first_name']; 
     $username = $_POST['username']; 
     $password = $_POST['password']; 


    $query = "SELECT username FROM user WHERE username ='$username'"; 
     $result = mysqli_query($link, $query) ; 

     if (mysqli_num_rows($result) >= 1) { 
      echo $message ="WARNING: Name already exist <br/>"; 
      echo $message = "<a href='register.php'>Return</a>"; 

     } 
     else { 
     $queryInsert = "INSERT INTO user ( first_name,last_name,profession,gender,date_of_birth,country_of_residence,em ail,username,password)" . 
        "VALUES ('$first_name', '$last_name', '$profession', '$gender', '$date_of_birth', '$country_of_residence', '$email', '$username', '$password')"; 
     //echo $queryInsert; 
     //echo $queryInsert; 
     $resultInsert = mysqli_query($link,$queryInsert); 
     header('Location: login.php'); 
      echo "<h3>The following user has been successfully added: </h3>"; 

    } 


    ?> 

    Click <a href="admin.php"> here </a> to go back to the home page. 
</body> 

註冊PHP不斷有連接復位錯誤,每當試圖註冊

我一直在試圖使該寄存器PHP的工作,但不知何故,每當我進入的所有領域後,點擊進入,我得到這個錯誤:

The connection to the server was reset while the page was loading.

我一直在試圖找出哪裏有我的連接出錯了,但無濟於事。有人能給我一些指導嗎?

+0

不dbConnection.php設置'$ link'? – Gavriel

回答

0

你的文檔輸出到瀏覽器,這樣你就不能使用header功能,試試這個:

<?php 
    ob_start(); // TURN ON BUFFERING 
    session_start(); 
    include 'dbConnection.php'; 
    ?> 
    <!DOCTYPE HTML> 
    <html> 
    <head> 
     <title>Online Book Club</title> 

     </head> 

     <body> 
      <form method ="post" action ="register.php"> 

     <?php 
    //get the values from the form, using the POST method. 
    $first_name = $_POST['first_name']; 
    $last_name = $_POST['last_name']; 
    $profession = $_POST['profession']; 
    $gender = $_POST['gender']; 
    $date_of_birth = $_POST['date_of_birth']; 
    $country_of_residence = $_POST['country_of_residence']; 
    $email = $_POST['first_name']; 
    $username = $_POST['username']; 
    $password = $_POST['password']; 


     $query = "SELECT username FROM user WHERE username ='$username'"; 
    $result = mysqli_query($link, $query) ; 

    if (mysqli_num_rows($result) >= 1) { 
     echo $message ="WARNING: Name already exist <br/>"; 
     echo $message = "<a href='register.php'>Return</a>"; 

    } 
    else { 
    $queryInsert = "INSERT INTO user ( first_name,last_name,profession,gender,date_of_birth,country_of_residence,em ail,username,password)" . 
       "VALUES ('$first_name', '$last_name', '$profession', '$gender', '$date_of_birth', '$country_of_residence', '$email', '$username', '$password')"; 
    //echo $queryInsert; 
    //echo $queryInsert; 
    $resultInsert = mysqli_query($link,$queryInsert); 
    header('Location: login.php'); 
     echo "<h3>The following user has been successfully added: </h3>"; 

} 


?> 

Click <a href="admin.php"> here </a> to go back to the home page. 
</body> 
<?php 
    $output = ob_get_contents(); // GET THE CONTENT OF THE BUFFER 
    ob_end_clean(); // Get current buffer contents and delete current output buffer 
    echo $output; // OUTPUT THE BUFFER CONTENT TO THE BROWSER 
?>