<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>input</title>
</head>
<body>
<form method="POST" action="receive.php">
<p>您的姓名: <input type="text" name="T1" size="20"></p>
<p>您的性别:男<input type="radio" value="0" name="R1">
女<input type="radio" name="R1" value="1"></p>
<p>您的EMAIL:<input type="text" name="T2" size="35"></p>
<p>您的留言内容:</p>
<p> <textarea rows="16" name="S1" cols="45"></textarea></p>
<p> </p>
<p> <input type="submit" value="提交" name="B1">
<input type="reset" value="重置" name="B2"></p>
</form>
</body>
</html>
receive.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$ip=getenv(REMOTE_ADDR);
$sql = "INSERT INTO `guestbook`.`gbook` (`id`, `name`, `sex`, `email`, `info`, `ip`, `time_at`) VALUES (NULL, '$T1', '$R1', '$T2', '$S1', '$ip', NOW());";
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
mysql_query($sql);
$result=mysql_query("select * from $table");
while ($arr=mysql_fetch_array($result))
{
if ($arr[2]==0)
$gender='先生';
else
$gender='女士';
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>Receive</title>
</head>
<body style="background-attachment: fixed">
<table border="1" width="100%" id="table1" bgcolor="#FFFFFF">
<tr>
<td bordercolor="#FFFFFF" bgcolor="#C0C0C0"><?=$arr[6]?>(<?=$arr[5]?>)<p><?=$arr[1]?> <?=$gender?><<a href="<?=$arr[3]?>"><?=$arr[3]?></a>>
写到:</td>
</tr>
<tr>
<td><?=$arr[4]?><p> </p>
<p><a href="del.php?id=<?=$arr[0]?>">[删除]</a>
<a href="modify.php?id=<?=$arr[0]?>">[修改]</a>]</td>
</tr>
</table>
</body>
</html>
<?php
echo '<p>';
echo '<p>';
}
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body>
<p><a href="input.htm"><继续留言></a></p>
</body>
</html>
del.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$sql="DELETE FROM $table WHERE id=$id";
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
$result=mysql_query($sql);
if ($result)
echo "删除成功";
else
echo "删除失败";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body>
<p><a href="receive.php"><返回首页></a></p>
</body>
</html>
modify.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$ip=getenv(REMOTE_ADDR);
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);
$result=mysql_query("select * from $table where id=$id");
$arr=mysql_fetch_array($result);
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>input</title>
</head>
<body>
<form method="POST" action="modify_ok.php?id=<?=$id?>">
<p>您的姓名: <input type="text" name="T1" size="20" value="<?=$arr[1]?>"></p>
<p>您的性别:
<?php
if ($arr[2]==0) echo '男<input type="radio" value="0" name="R1" checked>
女<input type="radio" name="R1" value="1"></p>';
else echo '男<input type="radio" value="0" name="R1">
女<input type="radio" name="R1" value="1" checked></p>';
?>
<p>您的EMAIL:<input type="text" name="T2" size="35" value="<?=$arr[3]?>"></p>
<p>您的留言内容:</p>
<p> <textarea rows="16" name="S1" cols="45" ><?=$arr[4]?></textarea></p>
<p> </p>
<p> <input type="submit" value="修改" name="B1">
<input type="reset" value="重置" name="B2"></p>
</form>
</body>
</html>
modify_ok.php
<?php
$user='root';
$password='123';
$db='guestbook';
$table='gbook';
$connect=mysql_connect('localhost',$user,$password);
mysql_select_db($db);;
$sql = "UPDATE `guestbook`.`gbook` SET `name` = '$T1', `sex` = '$R1', `email` = '$T2', `info` = '$S1' WHERE `gbook`.`id` = '$id' LIMIT 1;";
$result=mysql_query($sql);
if ($result)
echo "修改成功";
else
echo "修改失败";
?>
<html>
<head>
<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>新建网页 1</title>
</head>
<body>
<p><a href="input.htm"><继续留言></a></p>
</body>
</html>
我自己有一个简单的留言板系统,
里面有简单的增删改查功能,需要会数据库。
希望可以帮助到有缘的学习爱好者。
这是首页index.php代码:
<html>
<head>
<title>我的留言本</title>
<script type ="text/javascript">
function dodel(id){
if(confirm("确定要删除吗?")){
window.location="action.php?action=del&id="+id;
}
}
</script>
<style type = "text/css">
*{font-family:"微软雅黑";}
body{
background:url(images/bg.gif);
}
a{color:#000;text-decoration:none;}
a:hover{text-decoration:underline;}
td{text-align:center;}
table{
border:3px solid #9b9b9b;
background:#E9E9E9;
}
td{
color:#660000;
}
</style>
</head>
<body>
<center>
<?php include("menu.php"); ?>
<h3>浏览新闻</h3>
<table width ="880" border="1" cellpadding="3">
<tr>
<th>新闻id</th><th>新闻标题</th><th>关键字</th><th>作者</th><th>发布时间</th><th>新闻内容</th><th>操作</th>
</tr>
<?php
//1.导入配置文件
require("dbconfig.php");
//2.链接mysql数据库,选择数据库
$link = @mysql_connect(HOST,USER,PASS)or die("数据库连接失败!");
mysql_select_db(DBNAME,$link);
//3.执行查询,并返回结果
$sql="select * from news order by addtime desc";
$result = mysql_query($sql,$link);
//4.解析结果集,并遍历输出
while($row = mysql_fetch_assoc($result)){
echo"<tr>";
echo"<td>{$row['id']}</td>";
echo"<td>{$row['title']}</td>";
echo"<td>{$row['keywords']}</td>";
echo"<td>{$row['author']}</td>";
echo"<td>{$row['addtime']}</td>";
echo"<td>{$row['content']}</td>";
echo"<td>
<a href='javascript:dodel({$row['id']})'>删除</a>
<a href='edit.php?id={$row['id']}'>修改</a></td>";
echo"</tr>";
}
//5.释放结果集
mysql_free_result($result);
mysql_close($link);
?>
</table>
</center>
</body>
</html>
<?php
// 引用相关文件
require("./conn.php");
require("./config.php");
// 确定当前页数 $p 参数
$p = $_GET['p']?$_GET['p']:1;
// 数据指针
$offset = ($p-1)*$pagesize;
$query_sql = "SELECT * FROM guestbook ORDER BY id DESC LIMIT $offset , $pagesize";
$result = mysql_query($query_sql);
// 如果出现错误并退出
if(!$result) exit('查询数据错误:'.mysql_error());
// 循环输出
while($gb_array = mysql_fetch_array($result)){
?>
<div class="guestbook-list">
<p class="guestbook-head">
<img src="images/<?=$gb_array['face']?>.gif" />
<span class="bold"><?=$gb_array['nickname']?></span> <span class="guestbook-time">[<?=date("Y-m-d H:i:s", $gb_array['createtime'])?>]</span><span> ID号:<?=$gb_array['id']?> 留言者IP:<?=$gb_array['clientip']?> <a href="reply.php?action=delete&id=<?=$gb_array['id']?>">删除留言</a> <a href="login.php?action=logout">注销登录</a></span></p>
<p class="guestbook-content"><?=nl2br($gb_array['content'])?></p>
<form id="form1" name="form1" method="post" action="reply.php">
<p><label for="reply">回复本条留言:</label></p>
<textarea id="reply" name="reply" cols="40" rows="5"><?=$gb_array['reply']?></textarea>
<p>
<input name="id" type="hidden" value="<?=$gb_array['id']?>" />
<input type="submit" name="submit" value="回复留言" />
</p>
</form>
</div>
<?php
} //while循环结束
?>
<div class="guestbook-list guestbook-page">
<p>
<?php
//计算留言页数
$count_result = mysql_query("SELECT count(*) FROM guestbook");
$count_array = mysql_fetch_array($count_result);
$pagenum = ceil($count_array['count(*)']/$pagesize);
echo '共 ',$count_array['count(*)'],' 条留言';
if ($pagenum > 1) {
for($i=1;$i<=$pagenum;$i++) {
if($i==$p) {
echo ' [',$i,']';
} else {
echo ' <a href="admin.php?p=',$i,'">'.$i.'</a>';
}
}
}
?>
<?php
if(isset($_POST['sub'])){
echo '标题:'.$_POST['title'].'<br />';
echo '姓名:'.$_POST['name'].'<br />';
echo '内容:'.$_POST['content'].'<br />';
}else{
?>
<!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>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
标题:<input type="text" name="title" /><br />
姓名:<input type="text" name="name" /><br />
内容<textarea name="content" cols="40" rows="5"></textarea><br />
<input type="submit" name="sub" value="留言" />
</form>
</body>
</html>
<?php
}
?>