- 相關(guān)推薦
php+mysql留言板系統(tǒng)「完整代碼及詳解」
學(xué)習(xí)php+mysql,留言板系統(tǒng)制作是重要的知識(shí)點(diǎn)。以下是由陽光網(wǎng)小編整理關(guān)于php+mysql留言板系統(tǒng)的內(nèi)容,希望大家喜歡!
php+mysql留言板系統(tǒng)【完整代碼及詳解】
主要頁面
input.html為初始頁
insert.php為把輸入內(nèi)容送入數(shù)據(jù)庫
show.php顯示留言板內(nèi)容
change.php修改留言板內(nèi)容的界面
del.php刪除留言板內(nèi)容
change_ok.php修改留言板內(nèi)容并送入數(shù)據(jù)庫
數(shù)據(jù)庫的創(chuàng)建
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 頁面
<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>你的'留言內(nèi)容:</p>
<p><textarea rows="9" name="info" cols="35"></textarea></p>
<p><input type="submit" value="提交" name="B1" /><input type="reset" value="重設(shè)" 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>陽光大學(xué)生網(wǎng)留言版</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>你的留言內(nèi)容:</p>
<p><textarea rows="9" name="info" cols="35"><?=$row[3]?></textarea></p>
<p><input type="submit" value="提交" /><input type="reset" value="重設(shè)" /></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>
看過“php+mysql留言板系統(tǒng)【完整代碼及詳解】”的人還看了:
1.php+mysql創(chuàng)建一個(gè)最簡(jiǎn)單留言板(完整代碼)
【php+mysql留言板系統(tǒng)「完整代碼及詳解」】相關(guān)文章:
大學(xué)文科專業(yè)及代碼04-03
qq情話留言板11-18
生日留言板祝福12-09
留言板愛情祝福04-02
程序員代碼面試指南11-26
大學(xué)專業(yè)詳解12-09
高考政策詳解04-02
qq留言板生日祝福04-01
qq留言板傷感短句04-05