开头红色的地方GET[ID],获取到了ID
但是后面红色的地方使用$ID时就出错了
大家帮忙看看是怎么一回事啊require "19-1.php";
require "19-3.php"; //调用头文件
$ID=$_GET[ID];
if(!$_POST[title]) //如果没有发送表单变量显示HTML
{
require "19-4.php";
echo "<center>\n";
echo "<table class=right_one>";
echo "<td width=\"70%\">";
echo "<table class=m border=1>\n";
require "19-1.php";$link=mysql_connect($host,$user,$pass);
mysql_select_db($db_name,$link);
$sql="select id from $table_gbook where nameid=$ID";
$result=mysql_query($sql,$link);
$msg_count=mysql_num_rows($result);//总条数
$p_count=ceil($msg_count/5);//总页数
echo "<tr>";
echo "<td class=header_5><center>全部留言</center></td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
if ($_GET["page"]==0 && !$_GET["page"])
$page=1;
else
$page=$_GET[page];
$s=($page-1)*5+1;
$s=$s-1;
$sql="select * from $table_gbook where nameid=$ID order by id desc limit $s";
$result=mysql_query($sql,$link);
$nums=mysql_num_rows($result);
if($nums<1) echo "还没有任何留言记录!";
else
{
while($rows=mysql_fetch_array($result))
{
echo "<br><h4><center>".$rows[title]."</center></h4>";
echo "<p>";
echo $rows[author]."于".$rows[date]."留言:";
echo "<p>";
echo "<p style=\"word-break:break-all\">".$rows[content]."</p>";
echo "<hr width=\"100%\">";
}
}
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td>";
$prev_page=$page-1;
$next_page=$page+1;
if ($page<=1){
echo "第一页 | ";
}
else{
echo "<a href='$PATH_INFO?ID=$ID&page=1'>第一页</a> | ";
}
if ($prev_page<1){
echo "上一页 | ";
}
else{
echo "<a href='$PATH_INFO?ID=$ID&page=$prev_page'>上一页</a> | ";
}
if ($next_page>$p_count){
echo "下一页 | ";
}
else{
echo "<a href='$PATH_INFO?ID=$ID&page=$next_page'>下一页</a> | ";
}
if ($page>=$p_count){
echo "最后一页</p>\n";
}
else{
echo "<a href='$PATH_INFO?ID=$ID&page=$p_count'>最后一页</a></p>\n";
}
echo "</td>";
echo "</tr>";
echo "</table>";
echo "<p>";
echo "<table class=m border=1>\n";
echo "<form action=19-17.php method=post>";
echo "<tr><td class=header_5>";
echo "<center>发表新留言</center>";
echo "</td></tr>";
echo "<tr><td>";
echo "留言题目:<input type=text name=title>";
echo "</td></tr>";
echo "<tr><td>";
echo "留言内容:<br><textarea class=text name=content rows=5></textarea>";
echo "</td></tr>";
echo "<tr><td>";
echo "<input type=submit value=\"发表\">";
echo "</td></tr>";
echo "</form>";
echo "</table>";
echo "</td>";
echo "</table>";
require "footer.php";
echo "</center>\n";
                         //?????,??
}
else //如果已经发送表单变量执行操作
{
$title=$_POST[title];
$content=$_POST[content];
$date=$date=date("Y年n月d日");
if(!$_COOKIE["username"])
 {
$username="匿名";
}
else
{
$username=$_COOKIE["username"];
}
$link=mysql_connect($host,$user,$pass);
mysql_select_db($db_name,$link);
$sql="insert into $table_gbook(name,author,title,content,date)values('$ID','$username','$title','$content','$date')";
mysql_query($sql,$link); //插入留言内容到表中
echo "<meta http-equiv=\"refresh\" content=\"2; url=19-17.php?ID=$ID\">";
echo "</head>\n";
echo "<body>\n";
echo "发表留言成功,正在返回";
echo "</body>";
echo "</html>";

?>开头红色的地方GET[ID],获取到了ID
但是后面红色的地方使用$ID时就出错了
大家帮忙看看是怎么一回事啊

解决方案 »

  1.   

    你把SQL语句输出看看,有没有什么问题,还有我注意到
    (name,author,title,content,date)values('$ID','$username','$title','$content','$date')这里面的参数对应嘛?
      

  2.   

    我晕了,单引号不解析php变量的
      

  3.   

    这样
    sql="insert into $table_gbook(name,author,title,content,date)values(".$ID.",'".$username."','".$title."','".$content."','".$date."')";
      

  4.   

    mysql_query($sql,$link) or die(mysql_error()); //插入留言内容到表中
      

  5.   

    Unknown column 'name' in 'field list'
    就是说传给name的那个$ID没有值
      

  6.   

    Unknown column 'name' in 'field list'表示数据表中没有'name'这个字段了
      

  7.   

    Unknown column 'name' in 'field list'
    未知列 'name' 在 'field list'
      

  8.   

    我已近解决了
    第一个就是name字段错了
    第二个是$ID在刷新后就没有了
    在第一个IF里POST一个$ID就OK了
    谢谢大家哈
    给大家一人一点分
    找到问题的多给点哈