「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());
}
?>