一共4个文件
inc.php 配置文件 内容是函数 和 连接数据库信息
add.php 发表文章文件
login.php 管理员登陆.退出文件
index.php 浏览 管理文件
数据库 phpgo
字段 类型 属性 Null 默认 额外 int(11) 否 auto_increment varchar(200) 否 varchar(6000) 否 int(10) 否 int(1) 否 varchar(30) 否 text 否
inc.php 配置文件 内容是函数 和 连接数据库信息
<?
$l="localhost";
$u="root";
$p="123456";
$k="test";
) or die("出错了".mysql_error());
) or die("出错了".mysql_error());
function go($str,$lei,$url){
switch ($lei){
case "go":
echo "<script language=\"javascript\">alert(\"$str\");location.href=\"$url\";</script>";
break;
case "back":
echo "<script language=\"javascript\">alert(\"$str\");history.go(-1);</script>";
break;
}
exit();
}
?>
add.php 发表文章文件
<?
include("fckeditor/fckeditor.php") ; // 引出 fckeditor 在线编辑器
if( isset($_POST['bt'])){
include("inc.php");
$bt=$_POST['bt'];
$nr=$_POST['nr'];
$tx=$_POST['tx'];
$xb=$_POST['xb'];
if($bt==""){go("请填写标题","back","");}
if($nr==""){go("请填写内容","back","");}
if($tx==""){go("请选择头像","back","");}
if($xb==""){ go("请选择性别","back","");}
$ip3=$_SERVER['REMOTE_ADDR'];
$str="insert into phpgo (bt,nr,tx,xb,ip) values ('$bt','$nr','$tx',$xb,'$ip3')";
@mysql_query($str,$conn)or die(mysql_error());
echo "加入".mysql_insert_id();
go("发表成功","go","index.php");
}
?>
<form name="form1" method="post" action="add.php">
<table width="524" height="298" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="99">标题</td>
<td width="310"><input type="text" name="bt" id="bt"></td>
<td width="115"></td>
</tr>
<tr>
<td>内容</td>
<td><?
$oFCKeditor = new FCKeditor('FCKeditor1') ; //创建fckeditor在线编辑器
$oFCKeditor->BasePath = 'FCKeditor/' ;
$oFCKeditor->ToolbarSet = 'Default' ;
$oFCKeditor->InstanceName = 'nr' ;
$oFCKeditor->Width = '700' ;
$oFCKeditor->Height = '400' ;
$oFCKeditor->Create() ;
// 没有在线编辑器 <textarea name="nr" ></textarea>
?>
</td>
<td></td>
</tr>
<tr>
<td>性别</td>
<td><input type="radio" name="xb" id="radio" value="1">
男
<input type="radio" name="xb" id="radio2" value="0">
女</td>
<td rowspan="2" align="center" valign="middle">
<img src="1.jpg" width="50" height="50" id="x"> </td>
</tr>
<tr>
<td>头像</td>
<td><select name="tx" id="tx" onChange="document.getElementById('x').src=this.vlaue;">
<option value="1.jpg">1</option>
<option value="2.jpg">2</option>
<option value="3.jpg">3</option>
<option value="4.jpg">4</option>
</select> </td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="button" id="button" value="提交"></td>
<td></td>
</tr>
</table>
</form>
login.php 管理员登陆.退出文件
<? //自己都觉得太能糊弄了.
session_start();
$id=intval($_GET['id']);
if ($id==1){
session_destroy();
echo "<script language=\"javascript\">alert(\"退出成功!\");location.href=\"index.php\";</script>";
}
else
{
$_SESSION['admin']=1;
echo "<script language=\"javascript\">alert(\"登陆成功!\");location.href=\"index.php\";</script>";
}
?>
index.php 浏览 管理文件
<?
session_start();
include_once("inc.php");
if (isset($_GET['del']))
{
$id=intval($_GET['del']);
$str="delete from phpgo where id=$id";
mysql_query($str,$conn) or die("删除失败!");
go("删除成功","go","index.php");
}
if (isset($_GET['edit']))
{
$id=intval($_GET['edit']);
$str="select * from phpgo where id=$id";
$rss=mysql_query($str,$conn) or die("查询失败!");
$rs=mysql_fetch_array($rss);
if($rs){
echo "<form name=\"form1\" method=\"post\" action=\"index.php?act=edit&id=$id\">";
echo "<table width=\"758\" height=\"222\" border=\"0\" cellpadding=\"0\" cellspacing=\"0\">";
echo " <tr> <td width=\"106\">标题</td>";
echo " <td width=\"352\">".$rs['bt']."</td>";
echo " </tr> <tr> <td>内容</td><td>".$rs['nr']."</td></tr><tr><td>性别</td><td>".$rs['xb']."</td></tr><tr>";
echo " <td>头像</td><td>".$rs['tx']."</td></tr><tr><td>IP</td>";
echo " <td>".$rs['ip']."</td></tr> <tr> <td>管理员回复</td> <td>";
echo " <textarea name=\"huifu\" cols=\"45\" rows=\"5\"></textarea>";
echo " <input type=\"submit\" name=\"button\" id=\"button\" value=\"提交\">";
echo " </td> </tr></table></form>";
}
else
{echo "没有这个记录";}
}
if (isset($_GET['act']))
{
$id=$_GET['id'];
$str="update phpgo set hf='".$_POST['huifu']."' where id=$id";
mysql_query($str,$conn) or die("更新失败!");
go("更新成功","go","index.php");
}
$ss=mysql_num_rows(mysql_query("select * from phpgo"));
echo "共有".$ss."条";
$page=isset($_GET['page'])?intval($_GET['page']):$page=1;
$countpage=ceil($ss/8);
if ($page>$countpage){$page=$countpage;}
if ($page<1){ $page=1;}
$offset=($page-1)*8; //偏移量
$str="select * from phpgo order by id desc limit $offset,8";
$rss=mysql_query($str,$conn);
echo "<table width=900 border=1 >";
echo "<tr><td>ID</td><td>标题</td><td>内容</td><td>头像</td><td>性别</td><td>IP</td><td>管理员回复</td>";
if ($_SESSION['admin']==1) { echo "<td>删除</td><td>修改回复</td>";}
echo "</tr>";
//mysql_fetch_row($rss) $rs['数值']
//mysql_fetch_array($rss) $rs['字段']
//mysql_fetch_object($rss) $rs->字段
while($rs=mysql_fetch_row($rss)){
echo "<tr>";
echo "<td>".$rs['0']."</td>";
echo "<td>".$rs['1']."</td>";
echo "<td>".$rs['2']."</td>";
echo "<td>".$rs['3']."</td>";
echo "<td>";
if($rs['4']==1)
{echo "男";}
else
{echo "女";}
echo "</td>";
echo "<td>".$rs["5"]."</td>";
echo "<td>";
if ($rs["6"]=="")
{echo "暂无";}
else
{echo $rs["6"];}
echo "</td>";
if ($_SESSION['admin']==1) {
echo "<td><a href=index.php?del=".$rs["0"].">删除</a></td>";
echo "<td><a href=index.php?edit=".$rs["0"].">修改</a></td>";
}
echo "</tr>";
}
echo "</table>";
mysql_close($conn);
if (isset($_SESSION['admin']))
{ echo "<a href='login.php?id=1' target='_top'>退出</a>";}
else
{ echo "<a href='login.php?id=0' target='_top'>登陆</a>";}
?>
<a href="add.php">留言</a>