PHP+MYSQL留言本(二) 打印 E-mail
  2008-01-02

今天再稍微改善下加一个管理员管理留言的功能~~~这里最主要要用到
$_SESSION[‘item‘] 这个东东~~`  好了`~`先把昨天的稍微改一下 再把这个功能加进去~~~
  首先我们在首页同时显示留言,以及留言添加框~~这样使留言者方便使用`~`
不说多了`~把代码贴出来再说:
index.php
<html>
<head>
<meta http-equiv="Content-Type" c>
<title>留言本</title>
</head>
<body>
<a href="admin_login.htm?sid=5ff1ca284ace1673275621303b17e7d6" tagert="_blank">留言管理</a>
   
   <?
     $conn=mysql_connect ("localhost:6033", "root", ""); //打开MySQL服务器连接
     mysql_select_db("guest_book"); //链接数据库
     mysql_query("set names GB2312"); //解决中文乱码问题
     $exec="select * from contents"; //sql语句
     $result=mysql_query($exec); //执行sql语句,返回结果
     while($rs=mysql_fetch_object($result)) 
    {
      echo "<table><tr><td>姓名:".$rs->name."</td></tr>";
      echo "<tr><td>留言:".$rs->content."</td></tr></table><br/>";
      echo ".............................................................................................................................";
    }
       mysql_close();
?>
<br><br><br>
<form action="updata.php" method="post" name="name1">
    姓名:<input type="text" name="user_name"><br>
    留言:<textarea name="post_contents" rows="10" cols="50"></textarea>
    <input type="submit" value="提交留言">
   </form>
</body>
</html>
updata.php页再加个header("location:index.php");语句重定向到主页面`~~
updata.php
<?
  $name=$_POST[‘user_name‘];
  $content=$_POST[‘post_contents‘];
  $conn=mysql_connect("localhost:6033", "root", "");
   mysql_query("set names GB2312"); //解决中文乱码问题
   mysql_select_db("guest_book");
   $exec="insert into contents (name,content) values (‘".$_POST[‘user_name‘]."‘,‘".$_POST[‘post_contents‘]."‘)";
   $result=mysql_query($exec);
   mysql_close();
   header("location:index.php");
?>

HOHO~~~是不是用起来有那么回事了`~~
好的`~下面再加个管理功能 ~~那么这个留言本就更加强大了`~
留言管理模块 分为 管理员登录页admin_login.htm ,管理员验证页admin_check.php  后台管理首页admin_index.php
先农这个登录页面admin_login.htm
<form action="admin_check.php" method="post" name="form2">
   用户名:<input type="text" name="admin_name">
   密  码:<input type="password" name="admin_password">
  <input type="submit" value="进入后台管理">
</form>
这个简单得再简单不过了,我就不说什么了`~~
admin_check.php管理员验证
<?
  session_start();
  $admin_name=$_POST[‘admin_name‘];
  $admin_password=$_POST[‘admin_password‘];
  $conn=mysql_connect ("localhost:6033", "root", "");
  mysql_select_db("guest_book");
  $exec="select * from admin where admin_name=‘".$admin_name."‘";
  $result=mysql_query($exec);
   if ($rs=mysql_fetch_object($result))
    { if ($rs->admin_password==$admin_password)
       {$_SESSION[‘admin‘]="OK";
        header("location:admin_index.php");
        }
      else echo"密码不正确";
    }
   else echo"用户名不正确";
  
   mysql_close();
?>


这里最主要的就是session~~~凡事要用到session的地方.在页面最开始处要加上这一句session_start();否则就无法使用~~那么session究竟是什么东东呢?由于网页的传输方式(也就是http这个东西) 不是永久连接的~~`所以服务器无法在两个不同页面之间传送变量`~~唉.我一下子也说不清楚`~~还是看看这里http://www.chinalinuxpub.com/read.php?wid=87
上面有很详细的介绍.反正就是用这个东西来验证管理员的身分了`~~
好了下面说后台管理主页面admin_index.php
<?
session_start();
if($_SESSION[‘admin‘]=="OK")
{
  $conn=mysql_connect ("localhost:6033", "root", "");
  mysql_select_db("guest_book");
  $exec="select * from contents";
  $result=mysql_query($exec);
  while($rs=mysql_fetch_object($result))
     {
      echo "<table><tr><td>姓名:".$rs->name."</td></tr>";
      echo "<tr><td>留言:".$rs->content."</td></tr></table><br/>";
      echo  "<a href=modify.php?id=".$rs->id." >修改</a>      <a href=delete.php?id=".$rs->id." >删除</a>";
     }
echo "<br><br><br><br><br><a href=index.php >回首页</a>";
}
mysql_close();
?>
这里最主要是这一句echo  "<a href=modify.php?id=".$rs->id." >修改</a>      <a href=delete.php?id=".$rs->id." >删除</a>";
用来向所连接到的地址传递参数~~看看下面的就知道有什么用了
modify.php
<?
session_start();
if($_SESSION[‘admin‘]=="OK")
{
  $conn=mysql_connect ("localhost:6033", "root", "");
  mysql_select_db("guest_book");
  $exec="select * from contents where id=".$_GET[‘id‘];  /*这里这个$_GET[‘id‘]就是取得从那个连接传递过来的参数拉 */
  $result=mysql_query($exec);
  $rs=mysql_fetch_object($result);
  $name=$rs->name;
  $content=$rs->content;
  $id=$rs->id;
?>
  <form action="modify2.php" method="post" name="name1">
    ID  :<?=$id?><input type=hidden name=id value=<?=$id?> >
    姓名:<?=$name?><br>
    留言:<textarea name="post_contents" rows="10" cols="50"><?=$content?></textarea>
    <input type="submit" value="提交修改">
   </form>
<?
  }
mysql_close();
?>
这里这个<?=$id> 其实就等于 echo $id
再看看最终的数据修改实现页面modify2.php
<?
session_start();
if($_SESSION[‘admin‘]=="OK")
{
  $conn=mysql_connect ("localhost:6033", "root", "");
  mysql_select_db("guest_book");
  $exec="select * from contents where id=".$_GET[‘id‘];
  $exec="update contents set content=‘".$_POST[‘post_contents‘]."‘ where id=".$_POST[‘id‘];
  $result=mysql_query($exec);
 
}
mysql_close();
header("location:admin_index.php");
?>
最后就是删除功能的实现了
delete.php
<?
session_start();
if($_SESSION[‘admin‘]=="OK")
{
  $conn=mysql_connect ("localhost:6033", "root", "");
  mysql_select_db("guest_book");
  $exec="delete from contents where id=".$_GET[‘id‘];
  mysql_query($exec);
  mysql_close();
header("location:admin_index.php");
}
?>

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
今天用到的知识如下:
1: session_start();  $_SESSION[‘变量名‘]=$变量名 或者 某一特定值
2: <a href="http://www.phpuse.com/content/view/7275/1/sid_5ff1ca284ace1673275621303b17e7d6.html#####.php?var=##">aaa</a>用这个方法来传递参数  同时用 $_GET[‘var‘]来接收传递过来的值
3: 数据修改 :$exec="update tablename set item1=‘".$_POST[‘item1‘]."‘ where ...";
4: 数据删除 :$exec="delete from tablename where...";

发表评论
网友评论
aabbcc
作者 访客 于 2008-11-08 14:07:30
澳洲留学中介北京留学中介法国留学中介韩国留学韩国留学中介合法留学中介荷兰留学中介荷兰预科留学服务留学公司留学咨询公司美国留学中介欧洲留学中介英国留学中介加拿大留学中介留学申请高中生留学|澳大利亚留学澳洲留学出国出国留学法国留学荷兰留学加拿大留学加拿大签证留学留学澳大利亚留学澳洲留学法国留学荷兰留学加拿大留学美国留学新加坡留学英国留学中介美国留学新加坡留学英国留学英国签证瑞典留学翻译公司翻译公司洁身器窃听器手机窃听器监听器手机监听器窃听器手机窃听器监听器手机监听器窃听器手机窃听器监听器手机监听器窃听器手机窃听器监听器手机监听器办证网上办证北京办证上海办证广州办证
onestoptown
作者 访客 于 2008-11-20 12:34:24
shoes online buy shoes sandal shoes slippers shoes ecco shoes rockport shoes
steve madden shoes - puma shoes -  
nike shoes  
nike shoes replica  
replica nike shoes
air jordan shoes  
replica watches rolex  
replica watch - rolex watch - fake rolex watches
oyster rolex  
rolex watches
replica watches
replica rolex watches - rolex replica - watches online
oyster rolex watch - quartz watch fake - nike shoes - nike shoes replica - replica nike shoes
air jordan shoes - replica watches rolex - replica watch - rolex watch - fake rolex watches
oyster rolex - rolex watches - replica watches - replica rolex watches - rolex replica - watches online
oyster rolex watch - quartz watch fake -  
best replica watches 
rolex watches - replica watches - replica nike shoes - jordan shoes - watches online
oyster rolex watch - quartz shoes fake -  
nike shoeses
dfdf
作者 访客 于 2008-11-24 14:56:10
我们企业电子商务主要服务于 
中国流水线行业网 
拓野流水线  
输送线 
生产线装配线 
组装流水线 
皮带流水线 
 
金信流水线  
金信输送设备 输送机 
工业流水线 自动化流水线 电动车流水线 
输送线 输送流水线 
金信生产线 生产流水线 
装配线装配 流水线 
生产流水线 
 
增盛流水线 
台州水泵 
 
自动生产线 生产线设备 
全自动生产线 装配生产线 
组装流水线 自动化流水线 电动车流水线 
装配流水线 生产流水线 电子产品流水线 板链线 
涂装流水线 包装流水线 装配线 
流水线设备 工业流水线 皮带流水线 
输送线 生产线输 送流水线 
 
雅龙流水线  
流水线 
雅龙生产线 
生产线 
输送设备 
生产流水线 
输送机 
输送线 
组装自动化流水线设备 
 
 
皮带输送线 生产线 输送流水线 
涂装流水线 包装流水线 装配线 
装配流水线 生产流水线 电子产品流水线 板链线 
自动化装配线 工业流水线 皮带流水线 
组装流水线 自动化流水线 电动车流水线 
 
板链线 流水线设备 皮带流水线 
输送线 输送流水线 皮带输送线 
板链线 流水线设备 皮带流水线 
流水线 工业流水线 自动化流水线 
生产线 组装流水线 自动化流水线 
 
生产线 
流水线设备 
流水线 
 
Replica Watches Jewelry Replica HandBags
作者 访客 于 2008-11-25 21:39:31
Replica Watches,Fake Watches,Replica Watch,Fake Watch,Wholesale Watches,Wholesale Replica Watches,Jewelry Watches,Replica Jewelry Watches. 
 
Replica Watches, Replica Watches, Fake Watches, Fake Watches, Replica Designer Handbags, Replica Designer Handbags, Replica Watches, Replica Watches, Replica Watches, Replica Watches, Replica Watches, Replica Watches, Replica Watch, Replica Watch, Wholesale Replica Watches, Wholesale Replica Watches, Replica Watches, Replica Watches, Replica Watches, Replica Watches, Concord Replica, Concord Replica, Citizen Replica, Citizen Replica, Tissot Watch Replica, Tissot Watch Replica, Panerai Watch, Panerai Watch, IWC Watch, IWC Watch, Breitling Watches Replica, Breitling Watches Replica, Fake Louis Vuitton, Fake Louis Vuitton, Fake A Lange Sohne Watch, Fake A Lange Sohne Watch, Gucci Watches, Gucci Watches, Replica Omega Watches, Replica Omega Watches, Zenith Replica Watch, Zenith Replica Watch, Replica Bvlgari, Replica Bvlgari, Fake Corum Watch, Fake Corum Watch, Fake Movado Watches, Fake Movado Watches, Replica IWC Watches, Replica IWC Watches, Franck Muller Replica, Franck Muller Replica, Fake Chopard Watches, Fake Chopard Watches, Fake Chopard, Fake Chopard, Rolex Replica, Rolex Replica, Fake Longines, Fake Longines,
Replica Watches Jewelry Replica HandBags
作者 访客 于 2008-11-25 23:58:18
Replica Watches,Fake Watches,Replica Watch,Fake Watch,Wholesale Watches,Wholesale Replica Watches,Jewelry Watches,Replica Jewelry Watches. 
 
Replica Watches, Replica Watches, Replica Watch, Replica Watch, Wholesale handbags, Wholesale handbags, Replica Watches, Replica Watches, Replica Handbag, Replica Handbag, Replica Watches, Replica Watches, Replica Watches, Replica Watches, Fake Watches, Fake Watches, Replica Watches, Replica Watches, Replica Handbags, Replica Handbags, Fake Breitling Watch, Fake Breitling Watch, Replica Panerai, Replica Panerai, Replica Patek Philippe, Replica Patek Philippe, Fake IWC, Fake IWC, Mont Blanc Replica Watches, Mont Blanc Replica Watches, Citizen Watches Replica, Citizen Watches Replica, Jacob Co Watch Replica, Jacob Co Watch Replica, Audemars Piguet Watches, Audemars Piguet Watches, Fake Chopard, Fake Chopard, Omega Watches, Omega Watches, Oris Watches Replica, Oris Watches Replica, Philip Stein Replica Watches, Philip Stein Replica Watches, Patek Philippe Watches, Patek Philippe Watches, Replica Philip Stein Watches, Replica Philip Stein Watches, Oris Replica Watch, Oris Replica Watch, Emporio Armani Replica Watches, Emporio Armani Replica Watches, Replica Cartier Watches, Replica Cartier Watches, Tissot Replica, Tissot Replica, Fake Franck Muller Watch, Fake Franck Muller Watch, Bvlgari Watch Replica, Bvlgari Watch Replica,
replica watches
作者 访客 于 2008-12-01 10:59:53
nike air jordan
nike sneaker -  
air force one shoes -  
nike womens -  
nike adidas -  
buy nike
nike sb 
nike shox 
men's puma shoes -  
timberland shoe -  
large shoes -  
nike football shoes
gucci shoes 
nike max 
Air jordan shoes
james sneaker -  
nike shoes -  
women shoes -  
adidas shoes -  
nike king
nike sneakers 
nike shox shoes 
puma shoes -  
timberland boat shoes -  
big shoes -  
football shoes
gucci man shoes 
nike nash 
 
 
 
swiss watch
sport shoe -  
replica watches -  
sports shoes -  
designer clothes
jewelry watches
replica shoes -  
watch repair -  
buy sport shoes -  
clothing store -  
 
footwear
nike dunk 
replica bag 
jewelry watch -  
fashion bag -  
seiko watch -  
replica watch
timex watch 
prada shoes 
 
 
replica rolex watches
-  
swiss  
 
replica watches
 
clothing store 
swiss  
 
replica watch
 
replica  
 
Gucci watch
 
replica  
 
rolex watch
 
replica watches 
Replica Handbags 
Rolex Sports Models 
 
 
 
nike james shoes 
nike max 
Areplica watches
james sneaker -  
swiss watch -  
replica shoes -  
clothes store 
www.watchinstyle.com
作者 访客 于 2008-12-01 14:02:44
wrist watches  
 
jewelry watches replica  
 
replica watches  
 
fine watches  
 
casio watches  
 
watches online 
 

quartz watch -  
 
quartz watch fake -  
 
nike shoes  
nike shoes replica  
replica nike shoes
air jordan shoes  
replica watches rolex  
replica watch - rolex  
 
watch
- fake rolex watches
oyster rolex  
rolex watches
replica watches
replica rolex watches -  
 
rolex replica
- watches online
oyster rolex watch - quartz  
 
watch fake
- nike shoes -  
 
nike shoes replica -  
 
replica nike shoes

air jordan shoes - replica  
 
watches rolex
- replica watch -  
 
rolex watch - fake rolex  
 
watches

oyster rolex -  
 
rolex watches -  
 
replica watches -  
 
replica rolex watches -  
 
rolex replica -  
 
watches online

oyster rolex watch -  
 
quartz watch fake -  
best replica watches 
rolex watches -  
 
replica watches -  
 
replica nike shoes -  
 
jordan shoes -  
 
watches online
oyster rolex watch -  
 
quartz shoes fake -  
best replica colth 
nike air jordan
nike sneaker -  
air force one shoes -  
nike womens -  
nike adidas -  
buy nike
nike sb 
nike shox 
men's puma shoes -  
timberland shoe -  
large shoes -  
nike football shoes
gucci shoes 
nike max 
Air jordan shoes
james sneaker -  
nike shoes -  
women shoes -  
adidas shoes -  
nike king
nike sneakers 
nike shox shoes 
puma shoes -  
timberland boat shoes -  
big shoes -  
football shoes
gucci man shoes 
nike nash 
swiss watch
sport shoe -  
replica watches -  
sports shoes -  
designer clothes -  
best replica watches 
jewelry watches
replica shoes -  
watch repair -  
buy sport shoes -  
clothing store -  
 
footwear
nike dunk 
replica bag 
jewelry watch -  
fashion bag -  
seiko watch -  
replica watch
timex watch 
prada shoes
www.watchinstyle.com
作者 访客 于 2008-12-01 14:02:44
wrist watches  
 
jewelry watches replica  
 
replica watches  
 
fine watches  
 
casio watches  
 
watches online 
 

quartz watch -  
 
quartz watch fake -  
 
nike shoes  
nike shoes replica  
replica nike shoes
air jordan shoes  
replica watches rolex  
replica watch - rolex  
 
watch
- fake rolex watches
oyster rolex  
rolex watches
replica watches
replica rolex watches -  
 
rolex replica
- watches online
oyster rolex watch - quartz  
 
watch fake
- nike shoes -  
 
nike shoes replica -  
 
replica nike shoes

air jordan shoes - replica  
 
watches rolex
- replica watch -  
 
rolex watch - fake rolex  
 
watches

oyster rolex -  
 
rolex watches -  
 
replica watches -  
 
replica rolex watches -  
 
rolex replica -  
 
watches online

oyster rolex watch -  
 
quartz watch fake -  
best replica watches 
rolex watches -  
 
replica watches -  
 
replica nike shoes -  
 
jordan shoes -  
 
watches online
oyster rolex watch -  
 
quartz shoes fake -  
best replica colth 
nike air jordan
nike sneaker -  
air force one shoes -  
nike womens -  
nike adidas -  
buy nike
nike sb 
nike shox 
men's puma shoes -  
timberland shoe -  
large shoes -  
nike football shoes
gucci shoes 
nike max 
Air jordan shoes
james sneaker -  
nike shoes -  
women shoes -  
adidas shoes -  
nike king
nike sneakers 
nike shox shoes 
puma shoes -  
timberland boat shoes -  
big shoes -  
football shoes
gucci man shoes 
nike nash 
swiss watch
sport shoe -  
replica watches -  
sports shoes -  
designer clothes -  
best replica watches 
jewelry watches
replica shoes -  
watch repair -  
buy sport shoes -  
clothing store -  
 
footwear
nike dunk 
replica bag 
jewelry watch -  
fashion bag -  
seiko watch -  
replica watch
timex watch 
prada shoes

发表评论
用户访客
标题
BBCode:Web AddressEmail AddressBold TextItalic TextUnderlined TextQuoteCodeOpen ListList ItemClose List
评论



下一篇 >