gpt4 book ai didi

php - 注册 php 在尝试注册时一直出现连接重置错误

转载 作者:行者123 更新时间:2023-11-30 22:26:28 24 4
gpt4 key购买 nike

<?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 工作,但不知何故每当我在输入所有字段后单击 enter 时,我都会收到此错误:

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

我一直在尝试找出我的连接哪里出了问题,但无济于事。有人可以给我一些指导吗?

最佳答案

你正在将文档输出到浏览器,所以你不能使用 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
?>

关于php - 注册 php 在尝试注册时一直出现连接重置错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35096926/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com