Php 准备语句致命错误

Php 准备语句致命错误,php,prepared-statement,Php,Prepared Statement,那么,您可以在$dbh <?php //Defining page title define('WEBSITE_TITLE', 'Register'); //Content location $content = 'content/register.php'; //Database connection try { $dbh = new PDO('mysql:host=localhost;dbname=saldev', 'admin', '420blazeit'); $

那么,您可以在
$dbh

<?php
//Defining page title
define('WEBSITE_TITLE', 'Register');

//Content location
$content = 'content/register.php';

//Database connection
try {
    $dbh = new PDO('mysql:host=localhost;dbname=saldev', 'admin', '420blazeit');
    $dbh = null;
} catch (PDOException $e) {
    die();
}

//Including website template
include_once 'template.php';


if(isset($_POST['submitRegister'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $password2 = $_POST['password2'];
    $email = $_POST['email'];
    $rank = 'user';


    $ins = $dbh->prepare("INSERT INTO 'users'('username', 'password', 'email', 'rank') VALUES (''username','password', 'email','user')");
    $ins->execute();
    echo 'Success! you have been register';
    header("Location: index.php");
    }
?>

此外,您不应该在mysql查询中使用表或列名。

您有两个单引号。替换

$dbh = null;


同时删除
$dbh=null

为什么要编写$dbh=null;??
$ins = $dbh->prepare("INSERT INTO 'users'('username', 'password', 'email', 'rank') VALUES (''username','password', 'email','user')");
$ins = $dbh->prepare("INSERT INTO users (username, password, email, rank) VALUES ('username','password', 'email','user')");