VIEW.PHP
<?php include "common_news.php"; ?>连接MYSQL
<html>
<head>
<title>新闻发布</title>
<SCRIPT language=JavaScript>
function view(Url)
{
popup=window.open(Url,"Displaywindow","left=30,top=30,width=600,height=400,toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes, resizable=no");
}
</SCRIPT>
</head><body bgcolor=#cccccc>
<center>
新闻列表
</center>
<?php
if ($page){ //////这个PAGE值拿不到!!! $query="select count(*) as total from news";
$result=mysql_query($query);
$message_count=mysql_result($result,0,"total");
$page_count=ceil($message_count/$page_size);
$offset=($page-1)*$page_size;
$query="select * from news order by id desc limit $offset, $page_size";
$result=mysql_query($query);
if($result){
$rows=mysql_num_rows($result);
$i=1;
?>
<?php
while($myrow=mysql_fetch_array($result)){
?>
<table width="422" border="0" cellspacing="1" cellpadding="1" align="center">
<tr>
<td width="277"><li><a href="javascript:view('view_d.php?recid=<?php echo $myrow[id] ?>');"><?php echo "$myrow[title]</a>($myrow[pub_time])"; ?></td>
</tr>
</table>
<?php
$i++;
if ($i<=$rows){
echo "";
}
}
?>
<?php
$prev_page=$page-1;
$next_page=$page+1;
?>
<center>
<?php
if ($page<=1){
echo "第一页";
}
else{
echo "<a href='$PATH_INFO?page=1'>第一页</a>";
}
echo " ";
if ($prev_page<1){
echo "上一页";
}
else{
echo "<a href='$PATH_INFO?page=$prev_page'>上一页</a>";
}
echo " ";
if ($next_page>$page_count){
echo "下一页";
}
else{
echo "<a href='$PATH_INFO?page=$next_page'>下一页</a>";
}
echo " ";
if ($page>=$page_count){
echo "最后一页";
}
else{
echo "<a href='$PATH_INFO?page=$page_count'>最后一页</a>";
}
}
else{
echo "<p align='center'>现在还没有新闻!/p>";
}
}
?>
<p> </p>
</body>
</html>-------------------------------------------------------------------<?php include "common_news.php"; ?>
<html>
<head>
<title>新闻发布</title>
</head>
<body bgcolor=#cccccc><?php
if ($pub){ $title=htmlspecialchars($title);
$detail=htmlspecialchars($detail);
$detail= str_replace ( "\n","<br>", $detail);
$pub_time=date("Y")."-".date("m")."-".date("d")." ".date("H").":".date("i").":".date("s");
$query="insert into news (title,detail,pub_time) values ";
$query.="('$title','$detail','$pub_time')";
$result=mysql_query($query,$db);
echo "<div align='center'>";
if ($result){
echo "<p>发布成功!<a href='view.php?page=1'>查看</a>、<a href='pub.php'>发布</a></p>";
}
else{
echo mysql_error();
echo "<p>发布失败!</p>";
}
echo "</div>";
}
?>
</body>
</html>
------------------------------------------------------------插入MYSQL的数据是空白,~~~~
<?php include "common_news.php"; ?>
<html>
<head>
<title>新闻发布</title>
</head>
<body bgcolor=#cccccc><?php
if ($pub){ $title=htmlspecialchars($title);
$detail=htmlspecialchars($detail);
$detail= str_replace ( "\n","<br>", $detail);
$pub_time=date("Y")."-".date("m")."-".date("d")." ".date("H").":".date("i").":".date("s");
$query="insert into news (title,detail,pub_time) values ";
$query.="('$title','$detail','$pub_time')";
$result=mysql_query($query,$db);
echo "<div align='center'>";
if ($result){
echo "<p>发布成功!<a href='view.php?page=1'>查看</a>、<a href='pub.php'>发布</a></p>";
}
else{
echo mysql_error();
echo "<p>发布失败!</p>";
}
echo "</div>";
}
?>
</body>
</html>
$page = $_GET['page'];
//...
}
关于插入数据库空白的问题,可以把涉及到数据库操作的语句后加入错误信息输出的代码,看看倒底是什么错误,比如:
$result=mysql_query($query,$db);
改为:
if (!$result = mysql_query($query,$db)) die(mysql_error());
另外,建议在php.ini中设置输出所有级别的错误信息以方便调试:
error_reporting = E_ALL
display_errors = On
英文:http://php.net/manual/en/security.globals.php
中文(不是最新的,没有提到这个配置项在PHP5.3.0以后已经被废除):http://www.php.net/manual/zh/security.globals.php
var_dump($_POST); // 看看post是否有内容
// 如果没有开启自动注册全局变量(不推荐用),那么使用都是直接用$_GET或者$_POST中的内容吧!
if (isset($_POST['pub'])){