我已经通过“include.php”将我的 PHP 与我的数据库链接起来,它正在连接到数据库。但是它没有使用以下注册 PHP 在表中创建数据。
<?php
if(isset($_POST['doRegister'])){
$username = $_POST['username'];
$password = $_POST['password'];
$verpassword = $_POST['verpassword'];
$email = $_POST['email'];
if(empty($username) || empty($password) || empty($verpassword) || empty($email)){
echo "Please fill in all fields!";
} else {
if($password == $verpassword){
include("include/db.php");
$result = $mysql->query("SELECT * FROM `users` WHERE `username`='$username'");
$numrows = $result->rowCount();
if($numrows != 0){
$res = $mysql->query("SELECT * FROM `users` WHERE `email`='$email'");
$nums = $res->rowCount();
if($nums != 0){
$stmt = $mysql->prepare("INSERT INTO `users` VALUES (:id,:username,:password,:email,:salt,:isBanned,:isAdmin)");
$newsalt = "$2a$07$".uniqid(mt_rand(), true)."$";
$enc_pass = crypt($password, $newsalt);
$stmt->execute(array(':id' => '',':username' => $username,':password' => $enc_pass,':email' => $email,':salt' => $newsalt,':isBanned' => '0',':isAdmin' => '0',));
echo "You have signed up successfully!";
} else {
echo "That username is already taken!";
}
} else {
echo "That email has already been registered! <a href='login.php'>login?</a>";
}
} else {
echo "Passwords do not match!";
}
}
}
?>
这是我的数据库连接php。
<?php
try {
$mysql = new pdo('mysql:host=*;dbname=*','*','*');
} catch (Exception $e){
die("Can't connect!".$e->getMessage());
}
?>