注册 | 登录 忘记密码? 51cto首页 | 博客 | 论坛 | 招聘
热点文章 小五思科技术学习笔记之SSH
 帮助

PHP入门-----简单留言本


2008-04-24 10:29:51
 标签:php 入门 留言本   [推送到技术圈]

版权声明:原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://approlife.blog.51cto.com/304821/73264
<!--function.php-->
<?php
    //header('Content-Type:text/html;charset:utf-8');
    error_reporting(0);
    class Con_sqlite
    {
  function get_sqlite_con()
  {
      $db=new SQliteDatabase('liuyan');
      $sql="create table liu (id integer primary key not null,name varchar(20),content varchar(500) )";
      $db->query($sql);
      /*$sql2="insert into liu (name,content) values('kk','ffffffdiekl')";
      $db->query($sql2);*/
      return $db;
  }
    }
?>
 
<!--index.php-->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
    //header('Content-Type:text/html;charset:utf-8');
    include('function.php');
    $db_sqlite=new Con_sqlite;
    $db=$db_sqlite->get_sqlite_con();
    $sql="select * from liu";
    $res=$db->query($sql);
    $arr=$res->fetchAll(SQLITE_ASSOC);
?>
<body>

<h3 align="center">简单留言本</h3>
<table align="center" width="700" bordercolor="#006666" border="1">
<?php
    foreach($arr as $row)
    {?>
  <tr><td>编号:<?=$row['id']?></td><td>标题:<?=$row['name'] ?></td><td align="right" width="50"><a href="del.php?id=<?=$row['id']?>">删除</a></td></tr>    <tr><td colspan="2" valign="top" height="50"><?=$row['content']?></td></tr>
    <?php
    }
?>
</table>
<h3 align="center" class="STYLE1">我要留言</h3>
<form id="form1" name="form1" method="post" action="add.php">
  <table width="700" border="1" align="center">
    <tr>
      <td width="15%" align="right" valign="bottom">姓名:</td>
      <td><input name="name" type="text" size="77" /></td>
    </tr>
    <tr>
      <td align="right" valign="bottom">内容:</td>
      <td><textarea name="content" cols="60" rows="8"></textarea></td>
    </tr>
    <tr>
      <td> </td>
      <td><input type="submit" name="Submit" value="提交" /></td>
    </tr>
  </table>
</form>
</body>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>发表留言</title>
</head>
<!--add.php-->
<body>
<?php
    include('function.php');
    $db_sqlite=new Con_sqlite;
    $db=$db_sqlite->get_sqlite_con();
    $name=$_POST['name'];
    $content=$_POST['content'];
    $add_sql="insert into liu (name,content) values ('$name','$content')";
    if($db->query($add_sql))
    {
  echo "<script>alert('留言成功')</script>";
  echo "<script>location.href='index.php'</script>";
    }
?>
</body>
</html>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>删除留言</title>
</head>
<!--del.php-->
<body>
<?php
    include('function.php');
    $db_sqlite=new Con_sqlite;
    $db=$db_sqlite->get_sqlite_con();
    $id=$_GET['id'];
    $del_sql="delete from liu where id=$id";
    if($db->query($del_sql))
    {
  echo "<script>alert('删除成功')</script>";
  echo "<script>location.href='index.php'</script>";
    }else
    {
  echo "<script>alert('删除失败');</script>";
  echo "<script>location.href='index.php'</script>";
    }
?>
</body>
</html>

本文出自 “技术旅途上蹒跚的步行者” 博客,请务必保留此出处http://approlife.blog.51cto.com/304821/73264





    文章评论
 
2008-04-24 10:35:10
希望能够多一些文字的说明 光看代码有点不明白效果

2008-04-24 16:32:05
OK。下次我会注意的。

 

发表评论

昵   称:
验证码:  点击图片可刷新验证码  博客过2级,无需填写验证码
内   容: