php - 注册 PHP sql 失败
问题描述
基本上我正在制作一个 PHP 注册脚本,但我得到“SQL 失败”,但所有细节都是正确的
我的代码
$link = mysqli_connect("localhost", "username", "password");
$database = mysqli_select_db($link, "database");
$user = mysqli_real_escape_string($link, $_GET['username']);
$password = mysqli_real_escape_string($link, $_GET['password']);
$table = "login";
$sql = "SELECT * FROM " . $table . " WHERE username=?";
$stmt = mysqli_stmt_init($link);
if (!mysqli_stmt_prepare($stmt, $sql))
{
echo "SQL Failed.";
} else {
mysqli_stmt_bind_param($stmt, "s", $user);
mysqli_stmt_execute($stmt);
Signupuser($user, $password, $table, $link);
}
function Signupuser($user, $password, $table, $link)
{
$options = ['cost' => 11];
$hashedPassword = password_hash($password, PASSWORD_BCRYPT, $options);
$sql = "INSERT INTO `" . $table . "` (username, password) VALUES (?, ?);";
$stmt = mysqli_stmt_init($link);
if (!mysqli_stmt_prepare($stmt, $sql))
{
echo "SQL Failed.";
} else {
mysqli_stmt_bind_param($stmt, "ss", $user, $hashedPassword);
mysqli_stmt_execute($stmt);
echo "User Created!";
}
}
但这会导致 SQL 失败,但所有细节都正确?难道我做错了什么...?
任何帮助和/或指示将非常感谢!
解决方案
推荐阅读
- mysql - 在 Mysql 中将“字符串”类型的列(包括括号)转换为日期时间
- matlab - fplot 为空矩阵创建问题
- facebook - 连接到 Facebook 的 API
- android - 在项目':app'中找不到任务'installDebug' - 创建项目后运行android
- scala - 模式匹配 Scala 案例类仅捕获一个字段
- firebase - 在 Firebase Cloud Firestore 中创建文档时生成 PDF
- xml - 创建新元素后删除空 XML 元素
- sql - 试图更新 SQL 数据,但数据包含有很多 ' 所以我得到错误
- python - 谷歌 API 服务帐户。即使使用域范围委派访问,也只能看到服务帐户驱动器
- laravel - 使用 eloquent ORM 在 laravel 中创建一个数组以生成层次树结构