有谁知道为什么 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';}
?>