我正在制作forum with reply function
但在我进入回复论坛后,它显示为 this:
这是我的代码:
<?php
session_start();
date_default_timezone_set('Asia/Hong_Kong');
include 'connect.php';
include 'header.php';
echo'<div id="content">';
$sql= "SELECT
topic_id,
topic_subject
FROM
topics
WHERE
topics.topic_id = " . mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql);
if(!$result)
{
echo 'The topic could not be displayed, please try again later.' .
mysql_error();
}
else
{
if(mysql_num_rows($result) == 0)
{
echo 'This topic does not exist.';
}
else
{
while($row = mysql_fetch_assoc($result))
{
echo '<h2>' . $row['topic_subject'] . '</h2>';
}
}
}
$sql="SELECT
posts.post_topic,
posts.post_content,
posts.post_date,
posts.post_by,
users.user_id,
users.user_name
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.user_id
WHERE
posts.post_topic = " . mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql);
if(!$result)
{
echo 'The topic could not be displayed, please try again later.' .
mysql_error();
}
if(mysql_num_rows($result) == 0)
{
echo 'There are no topics in this category yet.';
}
else
{
echo'<table border="2">
<tr>
<th class="leftpart2">個朵</th>
<th class="rightpart2">講緊乜</th>
</tr>';
while($row = mysql_fetch_assoc($result))
{
echo '<tr>';
echo'<td>'.$row['user_name'].'<br>日期: '.$row['post_date'].'</td>';
echo'<td>'.$row['post_content'].'</td>';
echo'</tr>';
echo'</table>';
}
}
echo'<h2>我要回應</h2>';
echo'<form method="post" action="reply.php?id=5">
<p><textarea name="reply-content"></textarea></p>
<p><input type="submit" value="回應"/></p>
</form>';
echo'</div>';
?>
<?php
session_start();
include 'connect.php';
include 'header.php';
echo'<div id="content">';
有人直接调用该文件,我们不想要
if($_SERVER['REQUEST_METHOD'] != 'POST')
{
echo 'This file cannot be called directly.';
}
else
{
检查登录状态
if(!$_SESSION['signed_in'])
{
echo 'You must be signed in to post a reply.';
}
else
{
真实用户发布了真实回复
$sql = "INSERT INTO
posts(post_content,
post_date,
post_topic,
post_by)
VALUES ('" . $_POST['reply-content'] . "',
NOW(),
" . mysql_real_escape_string($_GET['id']) . ",
" . $_SESSION['user_id'] . ")";
$result = mysql_query($sql);
if(!$result)
{
echo 'Your reply has not been saved, please try again later.';
}
else
{
echo 'Your reply has been saved, check out <a href="topic.php?id=' . htmlentities($_GET['id']) . '">the topic</a>.';
}
}
}
echo'</div>';
?>
是第81行的错误:echo&#39;?
如果每个人都需要补充,请随时问我。
答案 0 :(得分:1)
$ result包含false。你还没有检查为什么它是假的,你可以通过mysql_error([link])或mysql_errno([link])来做。
如果无法插入新行,则插入进行错误返回,或者您无权更改该表!
您应该检查您是否有权限,并且是否有必须填写&#39;表中的列,因为某种原因缺少某个值而引发错误。
But avoid …
Asking for help, _clarification_, or responding to other answers.
但是,请告诉我们您的错误信息是什么。