請幫助,這是不插入到數據庫爲什麼這個PDO插入不起作用?
$dbh = new PDO('mysql:host=localhost;dbname=blog', root, root);
if($dbh){
// use the connection here
$stmt = $dbh->prepare("INSERT INTO comments (blog_id,dateposted,name,comment) VALUES (:blog_id,:dateposted,:name,:comment)");
$stmt->bindParam(':blog_id', $validentry);
$stmt->bindParam(':dateposted', NOW());
$stmt->bindParam(':name', $_POST['name']);
$stmt->bindParam(':comment', $_POST['comment']);
$stmt->execute();
// and now we're done; close it
}else{
echo mysql_error();
}
$dbh = null;
//redirect after posting
有什麼錯誤?如果沒有錯誤 - 那麼要麼你沒有看到它們,要麼沒有錯誤,代碼工作正常。 – zerkms 2011-05-10 03:51:26
沒有錯誤頁面只發布後空白 – ktm 2011-05-10 03:59:46
打開錯誤。在這裏討論了數百萬次。搜索error_reporting()+ display_errors。另請閱讀如何從PDO中檢索錯誤。 'mysql_error'與PDO – zerkms 2011-05-10 04:02:46