我已经按照本教程https://www.youtube.com/watch?v=xb8aad4MRx8&t=225s在网站上创建登录系统和注册表单。我在我的localhost上创建了它,它运行得很好。我已经尝试将其上传到我的网站我已经在我的服务器上创建了一个数据库并更改了PHP代码但是没有数据输入到数据库中。我的托管服务是1and1及以下是在PHP中链接数据库的代码的代码。密码已更改
<?php
$host_name = 'db706265806.db.1and1.com';
$database = 'db706265806';
$user_name = 'dbo706265806';
$password = 'PASSWORD';
$conn = mysqli_connect($host_name, $user_name, $password, $database);
这是注册表单的代码
<?php
if (isset($_POST['submit'])) {
include_once 'dbh-inc.php';
$first = mysqli_real_escape_string($conn, $_POST['first']);
$last = mysqli_real_escape_string($conn, $_POST['last']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$uid = mysqli_real_escape_string($conn, $_POST['uid']);
$pwd = mysqli_real_escape_string($conn, $_POST['pwd']);
//error handers
//check for empty fields
if (empty($first) || empty($last) || empty($email) || empty($uid) || empty($pwd)) {
header("Location: ../signup.php?signup=empty");
exit();
} else{
//check if input char are valid
if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last)) {
header("Location: ../signup.php?signup=invalid");
exit();
}
else {
//check if email is valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
header("Location: ../signup.php?signup=email");
exit();
} else{
$sql = "SELECT * FROM users WHERE user_uid='$uid'";
$result = mysqli_query($conn, $sql);
$resultCheck = mysqli_num_rows($result);
if ($resultCheck > 0) {
header("Location: ../signup.php?signup=usernametaken");
exit();
} else{
//hashing the password
$hashedPwd = password_hash($pwd, PASSWORD_DEFAULT);
//insert the user into db
$sql = "INSERT INTO users (user_first, user_last, user_email, user_uid, user_pwd) VALUES ('$first', '$last', '$email', '$uid', '$hashedPwd');";
$result = mysqli_query($conn, $sql);
header("Location: ../signup.php?signup=success");
exit();
}
}
}
}
} else{
header("Location: ../signup.php");
exit();
}
对于未输入数据的任何帮助都表示赞赏