ユーザーがサインアップ フォームにユーザー名、パスワード、電子メールを入力した後、2 つのデータベースを作成しようとしています。
以下の最初の MySQL クエリは動作します。ユーザーテーブルに情報を挿入します。
ただし、2 番目のクエリはそうではありません。確認メールでアカウントを確認するために使用できる確認テーブルに暗号化されたキーを挿入しようとしています。
PDO 例外メッセージは次のとおりです。
例外 'PDOException' とメッセージ 'SQLSTATE[42000]: 構文エラーまたはアクセス違反: 1064 SQL 構文にエラーがあります。Near 'key, email) VALUES ( '24', 'd96e77df9072c73da2612380a784f51b', 'r' at line 1' in C:\xampp\htdocs\tutorspot\sign -up-tutors\index.php:80 スタック トレース: #0 C:\xampp\htdocs\tutorspot\sign-up-tutors\index.php(80): PDOStatement->execute() #1 {main}
if($action['result'] != 'error'){
$password = md5($password . 'salty');
try
{
$sql = 'INSERT INTO user (fullname, username, email, password, active) VALUES (
:fullname,
:username,
:email,
:password,
0)';
$s = $pdo->prepare($sql);
$s->bindValue(':fullname', $_POST['fullname']);
$s->bindValue(':username', $_POST['username']);
$s->bindValue(':email', $_POST['email']);
$s->bindValue(':password', $password);
$s->execute();
//get the new user id
$userid = $pdo->lastInsertId();
}
catch (PDOException $e)
{
$error = 'Error inserting signup info.';
include $_SERVER['DOCUMENT_ROOT'] . '/tutorspot/inc/error.html.php';
exit();
}
//create a random key for confirmation
$key = $username . $email . date('mY');
$key = md5($key . 'salty');
//add info to confirm table
try
{
$sql = 'INSERT INTO confirm (userid, key, email) VALUES (
:userid,
:key,
:email)';
$s = $pdo->prepare($sql);
$s->bindValue(':userid', $userid);
$s->bindValue(':key', $key);
$s->bindValue(':email', $_POST['email']);
$s->execute();
}
catch (PDOException $e)
{
$error = 'Error inserting confirm info.';
include $_SERVER['DOCUMENT_ROOT'] . '/tutorspot/inc/error.html.php';
echo $e;
exit();
}
}