简体   繁体   English

致命错误:第 19 行在 C:\\xampp\\htdocs\\register.php 中抛出未捕获的异常“PDOException”

[英]Fatal error: Uncaught exception 'PDOException' thrown in C:\xampp\htdocs\register.php on line 19

I have received:我收到了:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax;致命错误:未捕获的异常 'PDOException' 带有消息 'SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误; check the manual that corresponds to your MariaDB server version for the right syntax to use near '5538ac14bb2ca7514f9f4d8826f3c45e'')' at line 1' in C:\\xampp\\htdocs\\register.php:19 Stack trace: #0 C:\\xampp\\htdocs\\register.php(19): PDO->exec('insert into use...') #1 {main} thrown in C:\\xampp\\htdocs\\register.php on line 19.检查与您的 MariaDB 服务器版本相对应的手册,以获取在 C:\\xampp\\htdocs\\register.php:19 中的第 1 行的 '5538ac14bb2ca7514f9f4d8826f3c45e'')' 附近使用的正确语法:#0 C:\\xampp\\ htdocs\\register.php(19): PDO->exec('insert into use...') #1 {main} 在第 19 行扔到 C:\\xampp\\htdocs\\register.php 中。

How can this be solved, like what should be done?这怎么解决,比如应该怎么做?

<?php
    session_start();

    // If the form has been submitted

    if (isset($_POST['submitted'])){

        // Create a database connection

        $db = new PDO("mysql:dbname=johnsoa7_db;host=localhost", "root", "");
        $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

        // Get and sanitise the inputs, we don't need to do
        // this with the password as we hash it anyway

        $safe_forename = $db->quote($_POST['forename']);
        $safe_lastname = $db->quote($_POST['lastname']);
        $safe_email = $db->quote($_POST['email']);
        $hashed_password = $db->quote(md5($_POST['password']));

        // Insert the entry into the database

        $query = "insert into users values (default, $safe_forename, $safe_lastname, $safe_email, '$hashed_password')";

        $db->exec($query);

        // Get the ID

        $id = $db->lastInsertId();

        // Output success or the errors

        echo "Congratulations! You are now registered. Your ID is: $id";
    }
?>

You have an error in this line:你在这一行有一个错误:

$query = "insert into users values (default, $safe_forename, $safe_lastname, $safe_email,'$hashed_password')";

default should be quoted if it is string.如果它是字符串,则应引用default

If it is a variable, you missed $ .如果它是一个变量,你就错过了$

Please see the comment by @ceejayoz:请参阅@ceejayoz 的评论:

As he said you don't need quoted around $hashed_password...正如他所说,您不需要在 $hashed_pa​​ssword 周围引用...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:未捕获的错误:调用成员函数 prepare() 在 null [C:\\xampp\\htdocs\\twitter\\core\\classes\\user.php on line 19] - Fatal error: Uncaught Error: Call to a member function prepare() on null [C:\xampp\htdocs\twitter\core\classes\user.php on line 19] 致命错误:带有消息“ SQLSTATE [HY000]:常规错误”的未捕获异常“ PDOException” .. C:\\ xampp \\ .. PDOStatement-&gt; fetch()..第83行 - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000]: General error' .. C:\xampp\..PDOStatement->fetch().. on line 83 致命错误:未捕获的错误:第 23 行的 Class &#39;User&#39; C:\\xampp\\htdocs\\gallery\\admin\\includes\\admin_content.php - Fatal error: Uncaught Error: Class 'User' C:\xampp\htdocs\gallery\admin\includes\admin_content.php on line 23 提交时数据不保存按有(注意:未定义索引:第 18 行 C:\\xampp\\htdocs\\CW\\register.php 中的名字 - Data not saving when submit is press having ( Notice: Undefined index: firstname in C:\xampp\htdocs\C.W\register.php on line 18 PHP 致命错误:未捕获错误:Class 在 C:\xampp\htdocs\server\pdf.php:5 中未找到“Mpdf\Mpdf” - PHP Fatal error: Uncaught Error: Class "Mpdf\Mpdf" not found in C:\xampp\htdocs\server\pdf.php:5 Fatal error: Uncaught Error: Call to a member function query() on null in C:\xampp\htdocs\shop\index.php - Fatal error: Uncaught Error: Call to a member function query() on null in C:\xampp\htdocs\shop\index.php 致命错误:未捕获的异常“PDOException” - Fatal Error: Uncaught exception 'PDOException' 致命错误:未捕获错误:在C:\\ xampp \\ htdocs \\ oophp \\ Home.php中调用成员函数connect()时为null - Fatal error: Uncaught Error: Call to a member function connect() on null in C:\xampp\htdocs\oophp\Home.php 致命错误:未捕获的错误:C:\xampp\htdocs\imagebob\google-drive.php:41 中未定义的常量“STDIN” - Fatal error: Uncaught Error: Undefined constant “STDIN” in C:\xampp\htdocs\imagebob\google-drive.php:41 Php 致命错误未捕获的 PDOException - Php fatal error Uncaught PDOException
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM