php - 无法将注册页面中的数据放入 Mysql 数据库(000webhost)
问题描述
我已经开始使用 000webhost 使我的网站在线。
因为 000webhost 有一个专用的 Mysql 用于他们的数据库,所以我从那里创建了一个与我拥有的相同的 Mysql(在 Xampp 中)。
问题是我做的注册 PHP 不再工作了。
这是我用于注册的 PHP。
<?php
session_start();
require "db_conn.php";
require_once "emailControl.php";
$error = array();
$username = "";
$email = "";
if (isset($_POST['signup-btn'])) {
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$passwordConf = $_POST['passwordConf'];
if (empty($username)) {
$error['username'] = "Username required";
}
if (empty($email)) {
$error['email'] = "Email required";
}
if (empty($password)) {
$error['password'] = "Password required";
}
if ($password !== $passwordConf) {
$error['password'] = "The passwords does not match";
}
$emailQuery = "SELECT * FROM users WHERE email=? LIMIT 1";
$stmt = $conn->prepare($emailQuery);
$stmt->bind_param('s', $email);
$stmt->execute();
$result = $stmt->get_result();
$userCount = $result->num_rows;
$stmt->close();
if ($userCount > 0) {
$error['email'] = "Email already exists";
}
$usernameQuery = "SELECT * FROM users WHERE user_name=? LIMIT 1";
$stmt = $conn->prepare($usernameQuery);
$stmt->bind_param('s', $username);
$stmt->execute();
$result = $stmt->get_result();
$userCount = $result->num_rows;
$stmt->close();
if ($userCount > 0) {
$error['username'] = "Username already exists";
}
if (count($error) === 0) {
$password = password_hash($password, PASSWORD_DEFAULT);
$token = bin2hex(random_bytes(50));
$verified = false;
$sql = "INSERT INTO users (user_name, email, verified, token, password) VALUES (?, ?, ?, ?, ?)";
$stmt = $conn->prepare($sql);
$stmt->bind_param('ssbss', $username, $email, $verified, $token, $password);
if ($stmt->execute()) {
$user_id = $conn->insert_id;
$_SESSION['id'] = $user_id;
$_SESSION['username'] = $username;
$_SESSION['email'] = $email;
$_SESSION['verified'] = $verified;
$_SESSION['message'] = "you are now logged in!";
$_SESSION['validate'] = "An email will be send to verify your account! please check your email and click the link inside.";
$_SESSION['validate1'] = "You are now verified! you can now enter and enroll for SHS in Theresian School of Cavite! Thank you and have a great day!";
header('location: index.php');
exit();
} else {
$error['db_error'] = "Database error: Failed to register";
}
}
}
我已经推断出注册网页中表单中的数据没有通过数据库,而只是显示 else 语句。
我不明白为什么这不起作用,因为当我尝试对我的计算机上的 Mysql 执行此操作时,它运行良好。
有谁知道为什么会这样?
解决方案
推荐阅读
- spring-boot - 在 kibana 中禁用获取错误插件案例
- server - 删除不必要的 DNS 记录?
- azure - Azure Luis 响应 403:超出每月总密钥配额限制
- javascript - 如何在计数器应用程序上保存计数并将该计数显示在显示先前计数的列表中?(使用反应)
- r - 显示由理论相关值和前四个滞后的置信限组成的图,以确定声明是否正确
- javascript - 将 v-model 值从数字转换为字符串
- java - 单击listView上的按钮后获取_id和位置项 - Android
- javascript - 将任意 Javascript 函数导入 Vue.js 组件
- html - 单一表单元素和响应宽度的初学者元素问题
- javascript - 使用 fetch() 进行 POST 时 TypeError: Failed to fetch 被抛出而不等待响应