当我试图在我的论坛中发布主题时,这就出现了:
列数与第1行的值计数不匹配
有人可以看到 ERROR 吗? Tnx :)
这是我的代码:
<?php
session_start();
if ($_SESSION['uid'] == "") {
header("Location: index.php");
exit();
}
if (isset($_POST['topic_submit'])) {
if (($_POST['topic_title'] == "") && ($_POST['topic_content'] == "")) {
echo "You did not fill in both fields. Please retun to the previous page.";
exit();
} else {
include_once("connect.php");
$cid = $_POST['cid'];
$title = $_POST['topic_title'];
$content = $_POST['topic_content'];
$creator = $_SESSION['uid'];
$sql = "INSERT INTO topics (category_id, topic_title, topic_creator, topic_date, topic_reply_date) VALUES ('".$cid."', '".$title."', '".$creator."', now(), now())";
$res = mysql_query($sql) or die(mysql_error());
$new_topic_id = mysql_insert_id();
$sql2 = "INSERT INTO posts (category_id, post_creator, post_content, post_date) VALUES ('".$cid."', '".$new_topic_id."', '".$creator."', '".$content."', now())";
$res2 = mysql_query($sql2) or die(mysql_error());
$sql3 = "UPDATE categories SET last_post_date=now(), last_user_posted='".$creator."' WHERE id='".$cid."', LIMIT 1";
$res3 = mysql_query($sql3) or die(mysql_error());
if (($res) && ($res2) && ($res3)) {
header("Location: view_topic.php?cid=".$cid."&tid=".$new_topic_id);
} else {
echo "There was a problem creating your topic. Please try again.";
}
}
}
?>
答案 0 :(得分:0)
这就是你的错误:
$sql2 = "INSERT INTO posts (category_id, post_creator, post_content, post_date) VALUES ('".$cid."', '".$new_topic_id."', '".$creator."', '".$content."', now())";
您要将5个值($cid
,$new_topic_id
,$creator
,$content
,now()
)插入4列(category_id
,{ {1}},post_creator
,post_content
)。因此列数
(4)与值计数(5)不匹配。
此外,您可能会遇到另一个错误,因为您在post_date
之前有一个额外的逗号:
LIMIT