-1

有谁知道为什么 INSERT 不起作用?我正在编写具有相同代码的教程,但我无法得到任何东西。

我将 print_r 扔在那里以验证我的 POST 信息是否被正确捕获......它是。我在这里失去理智了。任何帮助,将不胜感激。谢谢

    <?php

if ( $_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['title']) && !empty($_POST['content']) ) {

    include('config.php');

    try{
        $dbh = new PDO(DB_NAME,DB_USER,DB_PASS);



    } catch (PDOException $e){

        echo $e->getMessage();
    }

    $title = $_POST['title'];
    $content = $_POST['content'];


    $stmt = $dbh->prepare(' INSERT INTO posts (title, content, created_at, updated_at) VALUE (?, ?, now(), now() ) ');

    $bindings = array($title, $content);

    $stmt->execute($bindings);
    print_r($stmt);

} else { echo 'fail';}

?>
4

2 回答 2

2

You need to use the keyword VALUES not VALUE

Also, you should really back tick your column and table names. (`)

于 2013-03-24T23:54:41.860 回答
1

INSERT INTO posts (title, content, created_at, updated_at) VALUES (?, ?, now(), now())

Use this as your Insert statement

于 2013-03-24T23:56:54.147 回答