php - 无法获取存储在 MySQL 数据库中的信息
问题描述
我在将代码发布到我的 MySQL 数据库时遇到问题,我们的网站没有返回任何错误,只是“注册成功”任何帮助将不胜感激!
如果需要任何其他详细信息,我可以发布更多代码来提供帮助。我对网站建设非常陌生,我被合法地卡住了。
谢谢 :)
这是发生了什么的剪辑:https ://www.youtube.com/watch?v=xhU67GD5niI
<?php
include_once 'db_connect.php';
include_once 'psl-config.php';
$error_msg = "";
if (isset($_POST['username'], $_POST['email'], $_POST['twitch'], $_POST['p'])) {
// Sanitize and validate the data passed in
$username = filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING);
$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
$email = filter_var($email, FILTER_VALIDATE_EMAIL);
$twitch = filter_input(INPUT_POST, 'twitch', FILTER_SANITIZE_STRING);
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Not a valid email
$error_msg .= '<p class="error">The email address you entered is not valid</p>';
}
$password = filter_input(INPUT_POST, 'p', FILTER_SANITIZE_STRING);
if (strlen($password) != 128) {
// The hashed pwd should be 128 characters long.
// If it's not, something really odd has happened
$error_msg .= '<p class="error">Invalid password configuration.</p>';
}
// Username validity and password validity have been checked client side.
// This should should be adequate as nobody gains any advantage from
// breaking these rules.
//
$prep_stmt = "SELECT id FROM members WHERE email = ? LIMIT 1";
$stmt = $mysqli->prepare($prep_stmt);
if ($stmt) {
$stmt->bind_param('s', $email);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows == 1) {
// A user with this email address already exists
$error_msg .= '<p class="error">A user with this email address already exists.</p>';
}
} else {
$error_msg .= '<p class="error">Database error</p>';
}
// TODO:
// We'll also have to account for the situation where the user doesn't have
// rights to do registration, by checking what type of user is attempting to
// perform the operation.
if (empty($error_msg)) {
// Create a random salt
$random_salt = hash('sha512', uniqid(openssl_random_pseudo_bytes(16), TRUE));
// Create salted password
$password = hash('sha512', $password . $random_salt);
// Insert the new user into the database
if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password, salt, twitch) VALUES (?, ?, ?, ?, ?)")) {
$insert_stmt->bind_param('sssss', $username, $email, $password, $random_salt, $twitch);
// Execute the prepared query.
if (! $insert_stmt->execute()) {
header('Location: ../eh/error.php?err=Registration failure: INSERT');
exit();
}
}
header('Location: ./register_success.php');
exit();
}
}
解决方案
我已经弄清楚了,我的数据库存在配置问题,重新创建后,我修复了它。谢谢您的帮助
推荐阅读
- amazon-web-services - 如何从爱尔兰地区的多个地区(弗吉尼亚北部和爱尔兰)获取 X-RAY 数据。我怎么能这样做?有什么建议吗?
- c# - 我是否违反了 DI 模式规则
- c# - AutoMapper,SelectMany 我得到各种元素编号
- excel - 复制一系列过滤的单元格
- java - !strcmp(locale, "C"):Error:Assert failed:in file baseapi.cpp, line 209
- reactjs - 如何使用 mobx 观察可观察数组上的 object.property 变化
- kotlin - 如何在 WebUI 中渲染 StreamObserver (ktor + freemarker)
- node.js - 如何从我的服务器中忽略或删除 dns 缓存浏览器?
- python - Python gui 应用工具?
- c# - Specflow 覆盖原始异常堆栈跟踪