我已经检查了一遍又一遍。我不准备使用准备好的语句,因此除非我做错了什么。
在添加所有字段之前,此方法有效。它只是用户名和密码时有效。 -我检查了我所有的文本框名称,它们都匹配。我的数据库列名称也与代码完全匹配。
有人可以帮帮我吗?我以这个准备好的陈述胡言乱语结束了,我准备跳船了。
<?php
session_start();
require 'lib/password.php';
require 'connect.php';
if(isset($_POST['register'])){
$username = !empty($_POST['username']) ? trim($_POST['username']) : null;
$pass = !empty($_POST['password']) ? trim($_POST['password']) : null;
$email = !empty($_POST['email']) ? trim($_POST['email']) : null;
$firstname = !empty($_POST['firstname']) ? trim($_POST['firstname']) : null;
$lastname = !empty($_POST['lastname']) ? trim($_POST['lastname']) : null;
$profileurl = !empty($_POST['profileurl']) ? trim($_POST['profileurl']) : null;
$steam64id = !empty($_POST['steam64id']) ? trim($_POST['steam64id']) : null;
$steamurl = !empty($_POST['steamurl']) ? trim($_POST['steamurl']) : null;
$sql = "SELECT COUNT(username) AS num FROM users WHERE username = :username";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':username', $username);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row['num'] > 0){
alert("Username already exists!");
die();
}
$sql = "SELECT COUNT(email) AS num FROM users WHERE email = :email";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':email', $email);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row['num'] > 0){
alert("Email already exists!");
die();
}
$passwordHash = password_hash($pass, PASSWORD_BCRYPT, array("cost" => 12));
$sql = "INSERT INTO users (firstname, lastname, email, password, truckermpurl, steam64id, steamurl, username) VALUES (:firstname, :lastname, :email, :password, :truckermpurl, :steam64id, steamurl, username)";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':firstname', $firstname);
$stmt->bindValue(':lastname', $lastname);
$stmt->bindValue(':email', $email);
$stmt->bindValue(':password', $passwordHash);
$stmt->bindValue(':truckermpurl', $profileurl);
$stmt->bindValue(':steam64id', $steam64id);
$stmt->bindValue(':steamurl', $steamurl);
$stmt->bindValue(':username', $username);
$result = $stmt->execute();
if($result){
//What you do here is up to you!
alert("Thanks for registering.");
exit();
}
}
?>
最佳答案
您期望参数
$stmt->bindValue(':steamurl', $steamurl);
$stmt->bindValue(':username', $username);
但是,您已经在准备好的语句中声明了SQL
... , steamurl, username)"
应该是
... , :steamurl, :username)"
关于php - 如何解决内部服务器错误-PHP?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48472182/