0
我想創建一個基本的博客,我已經完全按照以前的項目插入到mysql數據庫的語法,但是這不會添加。我回應了值,看看它是否正確傳遞,但是當我檢查我的數據庫時,什麼都沒有添加。有沒有人可以看到我的代碼有問題?無論你是否能夠提供幫助,都要事先感謝任何回答問題的人。PDO沒有插入數據庫,但有正確的值
編輯:我也檢查了我的數據庫,它工作正常,並且是named,也connect.php適用於我的登錄,因爲信息是相同的,它應該在這裏工作。
EDIT2:數據庫表如下
postid int(10) auto_increment
title text
author text
date date
content text
tag1 text
tag2 text
<?php
// Make sure the user is logged in
session_name('blog');
session_start();
if (empty($_SESSION['username']))
{
header("Location: loginhome.php");
exit;
}
// Connect to the database and add a message
include("connect.php");
$one = $_POST['title'];
$two = $_POST['author'];
$three = $_POST['content'];
$four = $_POST['cat1'];
$five = $_POST['cat2'];
echo $two;
$add_message_query = $db->prepare("
INSERT INTO `blogposts`
(`title`, `author`, `date`, `content`, `tag1`, `tag2`)
VALUES
(:title, :author, CURRENT_TIMESTAMP, :content, :cat1, :cat2)
");
$add_message_query->execute(
array(
':author' => $one,
':title' => $two,
':content' => $three,
':cat1' => $four,
':cat2' => $five
)
);
//go to home to show new post
//header("Location: home.php");
?>
你用'的var_dump($ DB-> ERRORINFO())'和'的var_dump($ add_message_query-> ERRORINFO())'得到什麼? – andrewsi 2013-05-05 01:32:21
你確實注意到你將'$ _POST ['title']'作爲':author'插入了嗎? 此外,我個人更喜歡'NOW()'在'CURRENT_TIMESTAMP'和'varchar'上方的'text'字段中少於500個字符,如標題和作者。 – Thorbear 2013-05-05 01:33:52
asfasfsarray(3){[0] => string(5)「23000」[1] => int(1048)[2] => string(28)「列'tag1'不能爲空」當我做var_dump($ add_message_query-> ErrorInfo()),我沒有看到我切換非常感謝你 – Chris 2013-05-05 01:39:17