当页面加载php错误时,重置了与服务器的连接

时间:2016-01-30 07:12:37

标签: php database mysqli

<?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 account WHERE username = '$username' ";
        $result = mysqli_query($link, $query) ;  

        $queryInsert = "INSERT INTO user (first_name,last_name,profession,gender,date_of_birth,country_of_residence,email,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>
</html>

永远存在该错误消息。无法找出我的连接或代码出错的地方。有人介意帮我吗?真的不能想到我的错误在哪里。无法破译它是否是连接或代码问题。

1 个答案:

答案 0 :(得分:1)

您已在代码中添加此行。  header('Location:login.php');

这意味着该页面将重定向到login.php。如果您将上述页面命名为login.php,则会形成重定向循环(再次重定向到同一页面)。因此浏览器无法呈现该页面。