有沒有人知道爲什麼INSERT不起作用?我正在使用相同代碼的教程,但我無法獲取任何插件。使用PDO插入不起作用
我扔了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';}
?>
你能添加print_r的輸出? – hek2mgl 2013-03-24 23:53:51
PDOStatement對象([queryString] => INSERT INTO帖子('title','content','created_at','updated_at')VALUES(?,?, NOW(),NOW())) – Jonathan 2013-03-25 00:01:04