求用PHP写一个简单基本的留言板代码,有点急
留言板中要求有以下功能:留言,查看,管理员登录,后台管理(增,删,改留言等)我要代码,不要太复杂那种,只要简单并且拥有以上功能的代码就行。【还要连接上数据库】写得符合内容...
留言板中要求有以下功能:留言,查看,管理员登录,后台管理(增,删,改留言等)
我要代码,不要太复杂那种,只要简单并且拥有以上功能的代码就行。【还要连接上数据库】
写得符合内容的话另加100分 展开
我要代码,不要太复杂那种,只要简单并且拥有以上功能的代码就行。【还要连接上数据库】
写得符合内容的话另加100分 展开
1个回答
展开全部
数据库的创建
CREATE DATABASE GBOOK;
CREATE TABLE `gbook` (
`id` INT( 255 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 10 ) NOT NULL ,
`sex` TINYINT( 1 ) UNSIGNED NOT NULL ,
`email` VARCHAR( 255 ) NOT NULL ,
`info` TEXT NOT NULL ,
`ip` VARCHAR( 15 ) NOT NULL ,
`time_at` DATETIME NOT NULL
)
主要页面有:
input.html为初始页
insert.php为把输入内容送入数据库
show.php显示留言板内容
change.php修改留言板内容的界面
del.php删除留言板内容
change_ok.php修改留言板内容并送入数据库
input.html
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312" />
<title>留言版</title>
</head>
<body>
<form name="form1" method="post" action="insert.php">
<p>你的名字:<input type="text" name="name" size="20" /></p>
<p>你的性别:<input type="radio" value="1" name="sex" checked="checked" />男生 <input type="radio" value="0" name="sex" />女生 </p>
<p>你的E-mail:<input type="text" name="email" size="20" /></p>
<p>你的留言内容:</p>
<p><textarea rows="9" name="info" cols="35"></textarea></p>
<p><input type="submit" value="提交" name="B1" /><input type="reset" value="重设" name="B2" /></p>
</form>
</body>
</html>
insert.php
<?php
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$ip = getenv('REMOTE_ADDR');
$conn = mysql_connect("localhost","root","123456");
mysql_select_db("gbook");
$sql = "INSERT INTO `gbook` ( `id` , `name` , `sex` , `email` , `info` , `ip` , `time_at` )
VALUES (NULL , '$name', '$sex', '$email', '$info', '$ip', NOW( ))";
$result = mysql_query($sql,$conn);
$id = mysql_insert_id();
mysql_close($conn);
?>
<p>留言成功</p>
<p><a href="show.php">去留言页 </a></p>
show.php
<?
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "SELECT * FROM gbook ORDER BY 'id' DESC"; //排序 后留言的在前面显示
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
while($row = mysql_fetch_row($result))
{ // ----if语句判断男女------
if($row[2]==1)
{ $gender = '男';}
else
{ $gender = '女'; }
?>
<table width="752" border="1">
<tr>
<td height="32"><p><?=$row[6]?> <?=$row[5]?> </p>
<p><?=$row[1]?>(<?=$gender?>) <?=$row[3]?></p></td>
</tr>
<tr>
<td height="45"><?=nl2br($row[4])?><p><a href="change.php?id=<?=$row[0]?>">[修改]</a> <a href="del.php?id=<?=$row[0]?>">[删除]</a></p></td>
</tr>
</table>
<hr />
<?
}
mysql_free_result($result);
?>
change.php
<?
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "SELECT name, sex, email, info FROM gbook WHERE id = '$id' ";
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312" />
<title>留言版</title>
</head>
<body>
<form name="form1" method="post" action="change_ok.php?id<?=$id?>">
<p>你的名字:<input type="text" name="name" size="20" value="<?=$row[0]?>"/></p>
<?
// -----if语句判断男女 1为男 0为女-------
if($row[1]==1)
echo ' <p>你的性别:<input type="radio" value="1" name="sex" checked="checked" />男 <input type="radio" value="0" name="sex" />女 </p>';
else
echo ' <p>你的性别:<input type="radio" value="1" name="sex" />男 <input type="radio" value="0" name="sex" checked="checked" />女 </p>';
?>
<p>你的E-mail:<input type="text" name="email" size="20" value="<?=$row[2]?>"/></p>
<p>你的留言内容:</p>
<p><textarea rows="9" name="info" cols="35"><?=$row[3]?></textarea></p>
<p><input type="submit" value="提交" /><input type="reset" value="重设" /></p>
</form>
</body>
</html>
del.php
<?
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "DELETE FROM gbook WHERE id = '$id' ";
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
mysql_close($conn);
?>
<p><a href="show.php">[返回]</a></p>
change_ok.php
<?
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "UPDATE `gbook` SET `name` = '$name',`sex` = '$sex',`email` = '$email',`info` = '$info' WHERE `id` ='$id' ";
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
mysql_close($conn);
?>
<p><a href="show.php">[返回]</a></p>
CREATE DATABASE GBOOK;
CREATE TABLE `gbook` (
`id` INT( 255 ) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`name` VARCHAR( 10 ) NOT NULL ,
`sex` TINYINT( 1 ) UNSIGNED NOT NULL ,
`email` VARCHAR( 255 ) NOT NULL ,
`info` TEXT NOT NULL ,
`ip` VARCHAR( 15 ) NOT NULL ,
`time_at` DATETIME NOT NULL
)
主要页面有:
input.html为初始页
insert.php为把输入内容送入数据库
show.php显示留言板内容
change.php修改留言板内容的界面
del.php删除留言板内容
change_ok.php修改留言板内容并送入数据库
input.html
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312" />
<title>留言版</title>
</head>
<body>
<form name="form1" method="post" action="insert.php">
<p>你的名字:<input type="text" name="name" size="20" /></p>
<p>你的性别:<input type="radio" value="1" name="sex" checked="checked" />男生 <input type="radio" value="0" name="sex" />女生 </p>
<p>你的E-mail:<input type="text" name="email" size="20" /></p>
<p>你的留言内容:</p>
<p><textarea rows="9" name="info" cols="35"></textarea></p>
<p><input type="submit" value="提交" name="B1" /><input type="reset" value="重设" name="B2" /></p>
</form>
</body>
</html>
insert.php
<?php
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$ip = getenv('REMOTE_ADDR');
$conn = mysql_connect("localhost","root","123456");
mysql_select_db("gbook");
$sql = "INSERT INTO `gbook` ( `id` , `name` , `sex` , `email` , `info` , `ip` , `time_at` )
VALUES (NULL , '$name', '$sex', '$email', '$info', '$ip', NOW( ))";
$result = mysql_query($sql,$conn);
$id = mysql_insert_id();
mysql_close($conn);
?>
<p>留言成功</p>
<p><a href="show.php">去留言页 </a></p>
show.php
<?
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "SELECT * FROM gbook ORDER BY 'id' DESC"; //排序 后留言的在前面显示
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
while($row = mysql_fetch_row($result))
{ // ----if语句判断男女------
if($row[2]==1)
{ $gender = '男';}
else
{ $gender = '女'; }
?>
<table width="752" border="1">
<tr>
<td height="32"><p><?=$row[6]?> <?=$row[5]?> </p>
<p><?=$row[1]?>(<?=$gender?>) <?=$row[3]?></p></td>
</tr>
<tr>
<td height="45"><?=nl2br($row[4])?><p><a href="change.php?id=<?=$row[0]?>">[修改]</a> <a href="del.php?id=<?=$row[0]?>">[删除]</a></p></td>
</tr>
</table>
<hr />
<?
}
mysql_free_result($result);
?>
change.php
<?
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "SELECT name, sex, email, info FROM gbook WHERE id = '$id' ";
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=GB2312" />
<title>留言版</title>
</head>
<body>
<form name="form1" method="post" action="change_ok.php?id<?=$id?>">
<p>你的名字:<input type="text" name="name" size="20" value="<?=$row[0]?>"/></p>
<?
// -----if语句判断男女 1为男 0为女-------
if($row[1]==1)
echo ' <p>你的性别:<input type="radio" value="1" name="sex" checked="checked" />男 <input type="radio" value="0" name="sex" />女 </p>';
else
echo ' <p>你的性别:<input type="radio" value="1" name="sex" />男 <input type="radio" value="0" name="sex" checked="checked" />女 </p>';
?>
<p>你的E-mail:<input type="text" name="email" size="20" value="<?=$row[2]?>"/></p>
<p>你的留言内容:</p>
<p><textarea rows="9" name="info" cols="35"><?=$row[3]?></textarea></p>
<p><input type="submit" value="提交" /><input type="reset" value="重设" /></p>
</form>
</body>
</html>
del.php
<?
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "DELETE FROM gbook WHERE id = '$id' ";
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
mysql_close($conn);
?>
<p><a href="show.php">[返回]</a></p>
change_ok.php
<?
$mysql_server_name = "localhost";
$mysql_username = "root";
$mysql_password = "123456";
$mysql_database = "gbook";
$sql = "UPDATE `gbook` SET `name` = '$name',`sex` = '$sex',`email` = '$email',`info` = '$info' WHERE `id` ='$id' ";
$conn = mysql_connect($mysql_server_name,$mysql_username,$mysql_password);
mysql_select_db($mysql_database,$conn);
$result = mysql_query($sql);
mysql_close($conn);
?>
<p><a href="show.php">[返回]</a></p>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询