一段时间以来,我一直停留在我的编码的这一部分上,因为更改要么出现语法错误,要么出现一条表明它是未知列的消息。我尝试过使用单引号和不使用单引号,我想我之前尝试过双引号但一无所获。我很确定问题出在查询部分,但目前我不确定。
include_once "library.php";
connectdatabase();
if (isset($_COOKIE['bunny_id'])) {
$poster = $_COOKIE['bunny_id'];
} else {
echo "Sorry, you need to login or sign up before you can post :C";
}
if (!empty($_POST['topic_name'])) {
$topic_name = "'" . addslashes($_POST['topic_name']) . "'";
} else {
$topic_name = 'NULL';
echo "Topic field is not filled :c \n";
exit;
}
if (!empty($_POST['post_content'])) {
$post_content = "'" . addslashes($_POST['post_content']) . "'";
} else {
$post_content = 'NULL';
echo "Post content is not filled :c \n";
exit;
}
$query = "INSERT INTO posts(messages_poster, messages_topic, messages_content) VALUES('$poster', '$topic_name', '$post_content')";
$query2 = mysql_query($query);
if (mysql_num_rows($query2) == 1) {
echo "Topic has been created~";
exit;
} else {
echo "Sorry, there's been an error :c";
}
编辑:我设法解决了这个问题。该问题与在代码的前面部分中添加引号后向“$topic_name”和“$post_content”添加单引号有关(较小的问题还涉及使用 mysql_num_rows 而不是 mysql_affected_rows)。现在可以正常运行了~