私はこのエラーを受け取ります:Uncaught exception 'PDOException'
私のPHPコードです。ここでPDO登録フォームエラー
は私のコードです:ここでは
<?php
session_start();
require 'connect.php';
if(isset($_POST['register'])){
$username = !empty($_POST['username']) ? trim($_POST['username']) : null;
$pass = !empty($_POST['password']) ? trim($_POST['password']) : null;
//Construct the SQL statement and prepare it.
$sql = "SELECT COUNT(username) AS num FROM user WHERE username = :username";
$stmt = $pdo->prepare($sql);
//Bind the provided username to our prepared statement. $stmt->bindValue(':username', $username);
//Execute.
$stmt->execute();
//Fetch the row.
$row = $stmt->fetch(PDO::FETCH_ASSOC);
if($row['num'] > 0){
die('That username already exists!');
}
//Prepare our INSERT statement.
//Remember: We are inserting a new row into our users table.
$sql = "INSERT INTO users (username, password) VALUES (:username, :password)";
$stmt = $pdo->prepare($sql);
//Bind our variables.
$stmt->bindValue(':username', $username);
$stmt->bindValue(':password', $passwordHash);
//Execute the statement and insert the new account.
$result = $stmt->execute();
//If the signup process is successful.
if($result){
//What you do here is up to you!
echo 'Thank you for registering with our website.';
}
}
?>
は完全なエラーです:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'user.user' doesn't exist' in C:\xampp\htdocs\simplereg\register.php:13 Stack trace: #0 C:\xampp\htdocs\simplereg\register.php(13): PDO->prepare('SELECT COUNT(us...') #1 {main} thrown in C:\xampp\htdocs\simplereg\register.php on line 13.
私は任意の助けをいただければ幸いです。
あなたのコードはきちんと整っていないので、Control + K –
を使ってコードをより美しく整頓した方がよいでしょう。明確に説明するために、タブ付きコードを正しく追加しました。 – theblindprophet