php留言板簡單
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>無標題文檔</title>
</head>
<body>
<BR><BR>
<center><a href="admin_login.htm" target="_blank">留言管理</a> </center><BR><BR>
<br><br><br>
<form method="post" >
<p>姓名:
<input type="text" name="user_name" size="20">
</p>
<p><br>
電話:
<input type="text" name="user_tel" size="20">
</p>
<p><br>
留言:
<textarea name="user_post" rows="5" cols="20"></textarea>
</p>
<p>
<input type="submit" value="提交留言" name="Submit">
</p>
</form>
<br><br><br>
<font color="red">最新留言如下:<BR><BR></font>
<?php
if($_POST['Submit']){
$user_name=$_POST['user_name'];
$user_tel=$_POST['user_tel'];
$user_post=$_POST['user_post'];
$ah=$_POST['ah'];
$where=$_POST['where'];
$str.="姓名:".$user_name."\r\n電話:".$user_tel."\r\n留言:".$user_post;
$k=fopen("liuyanban.txt","w+");
fwrite($k,$str);
fclose($k);
echo "保存成功!";
}
?>
</body>
</html>
㈡ php怎麼在mysql創建留言板步驟
工具:
Dreamweaver
php、mysql伺服器
步驟/方法
首先是確定自己的留言板需求.例如:名字,郵件及留言內容.
一. 建立一個資料庫guestbook。
CREATE TABLE IF NOT EXISTS `content` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(20) NOT NULL,
`email` varchar(50) NOT NULL,
`content` varchar(200) NOT NULL,
PRIMARY KEY (`id`))
ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=3;
二. 新建config.php
< ? php
$q = mysql_connect("伺服器","資料庫用戶","資料庫密碼");
if(!$q)
{
die('Could not connect: ' . mysql_error());
}
mysql_query("set names utf8"); //以utf8讀取數據
mysql_select_db("guestbook",$q); //資料庫
?>
三. 新建index.php
< ?php
include("config.php"); //引入資料庫連接文件
$sql = "select * from content"; //搜索數據表content
$resule = mysql_query($sql,$q);
?>
< html>
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
< body>
< table width="678" align="center">
< tr>
< td colspan="2">< h1>留言本< /h1>< /td>
< /tr>
< tr>
< td width="586">< a href="index.php">首頁< /a> | < a href="liuyan.php">留言< /a>< /td>
< /tr>
< /table>
< p>
< ?
while($row=mysql_fetch_array($resule))
{
?>
< /p>
< table width="678" border="1" align="center" cellpadding="1" cellspacing="1">
< tr>
< td width="178">Name:< ? echo $row[1] ?>< /td>
< td width="223">Email:< ? echo $row[2] ?>< /td>
< /tr>
< tr>
< td colspan="4">< ? echo $row[3] ?>< /td>
< /tr>
< tr>
< /table>
< ?
}
?>
< /body>
< /html>
四. 新建liuyan.php
< html>
< body>
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
< table width="678" align="center">
< tr>
< td colspan="2">< h1>留言本< /h1>< /td>
< /tr>
< tr>
< td width="586">< a href="index.php">首頁< /a> | < a href="liuyan.php">留言< /a>< /td>
< /tr>
< /table>
< table align="center" width="678">
< tr>
< td>
< form name="form1" method="post" action="post.php">
< p>
Name:
< input name="name" type="text" id="name">
< /p>
< p>Email:< input type="test" name="email" id="email">< /p>
< p>
留言:
< /p>
< p>
< textarea name="content" id="content" cols="45" rows="5">< /textarea>
< /p>
< p>
< input type="submit" name="button" id="button" value="提交">
< input type="reset" name="button2" id="button2" value="重置">
< /p>
< /form>
< /td>
< /tr>
< /table>
< /body>
< /html>
五. 新建post.php
< ?php
header("content-Type: text/html; charset=utf-8");
include("config.php");
$name= $_POST['name'];
$email= $_POST['email'];
$patch = $_POST['content'];
$content = str_replace("
","< br />",$patch);
$sql = "insert into content (name,email,content) values ('$name','$email','$content')";
mysql_query($sql);
echo "< script>alert('提交成功!返回首頁。');location.href='index.php';< /script>";
?>
這樣已經成功的寫出一個留言板了。
第二部分
此次將在上面版本上加多管理,回復等功能。
首先在sql中位元組。
ALTER TABLE `content` ADD `reply` VARCHAR( 200 ) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL AFTER `content`
一. 新建login.php
< html xmlns="http://www.w3.org/1999/xhtml">
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
< title>無標題文檔< /title>
< /head>
< body>< table width="678" align="center">
< tr>
< td colspan="2">< h1>留言本< /h1>< /td>
< /tr>
< tr>
< td width="586">< a href="index.php">首頁< /a> | < a href="liuyan.php">留言< /a>< /td>
< /tr>
< /table>
< table align="center" width="678">
< tr>
< td align="center">
< form name="form1" method="post" action="login2.php">
< label for="textfield">< /label>
< p> < /p>
< p>帳號:
< input type="text" name="name" id="name">
< /p>
< p>密碼:
< input type="password" name="pw" id="pw">
< /p>
< p>
< input type="submit" name="button" id="button" value="提交">
< input type="reset" name="button2" id="button2" value="重置">
< /p>
< /form>< /td>
< /tr>
< /table>
< /body>
< /html>
二.login2.php
< ?
session_start();
header("content-Type: text/html; charset=utf-8");
$name = $_POST['name'];
$pw = $_POST['pw'];
if($name == "admin" && $pw == "admin"){
$_SESSION["adminname"] = $name;
echo "< script>alert('登錄完成,返回首頁!');location.href='index.php';< /script>";
}else{
echo "< script>alert('錯誤!');location.href='login.php';< /script>";
}
?>
三. 在原有的index.php上添加
< ?php
session_start();
include("config.php");
$sql = "select * from content";
$resule = mysql_query($sql,$q);
?>
< html>
< meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
< body>
< table width="678" align="center">
< tr>
< td colspan="2">< h1>留言本< /h1>< /td>
< /tr>
< tr>
< td width="586">< a href="index.php">首頁< /a> | < a href="liuyan.php">留言< /a>< /td>
< td width="80">
// 新增管理員登錄
< ?php
if (isset($_SESSION['adminname']) && $_SESSION["adminname"] == "admin"){
echo "< a href='logout.php'>登出< /a>";
}else{
echo "< a href='login.php'>管理員登錄< /a>";
}
?>
< /td>
< /tr>
< /table>
< p>
< ?
while($row=mysql_fetch_array($resule))
{
?>
< /p>
< table width="678" border="1" align="center" cellpadding="1" cellspacing="1">
< tr>
< td width="178">Name:< ? echo $row[1] ?>< /td>
< td width="223">Email:< ? echo $row[2] ?>< /td>
< td width="100">
< ?php
if(isset($_SESSION['adminname']) && $_SESSION["adminname"] == "admin"){
echo "< a href='huifu.php?id=" . $row[0] . "'>回復< /a>";
echo " | " . "< a href='delete.php?id=" . $row[0] . "'>刪除< /a>";
} else {
echo "";
}
?>
< /td>
< /tr>
< tr>
< td colspan="4">< ? echo $row[3] ?>< /td>
< /tr>
< tr>
< td colspan="4">< ?
if($row[4] == ""){
?>
< ? echo "暫無回復。";?>
< ? }else {echo "管理員回復:". $row[4]; } ?>< /td>
< /tr>
< /table>
< ?
}
?>
< /body>
< /html>
四. 新建huifu.php
< ?php
include("config.php");
$sql = "select * from content where id=".$_GET["id"];
$resule = mysql_query($sql,$q);
SetCookie("id",$_GET["id"]);
session_start();
header("content-Type: text/html; charset=utf-8");
if(empty($_SESSION["adminname"])){
exit("< script language='javascript'>alert('您尚未登錄後台,或登錄已超時,請重新登錄!');window.location.href='login.php';< /script>");
}
?>
< !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>
< table width="678" align="center">
< tr>
< td colspan="2">< h1>留言本< /h1>< /td>
< /tr>
< tr>
< td width="586">< a href="index.php">首頁< /a> | < a href="liuyan.php">留言< /a>< /td>
< /tr>
< /table>
< table align="center" width="678">
< tr>
< td>
< form name="reply" method="post" action="reply.php" >
< p>回復:
< ?
while($row=mysql_fetch_array($resule))
{
echo $row[3];
}
?>
< /p>
< p>
< textarea name="reply" id="reply" cols="45" rows="5">< /textarea>
< /p>
< p>
< input type="submit" name="button" id="button" value="回復" />
< input type="reset" name="button2" id="button2" value="重置" />
< /p>
< /form>
< /td>
< /tr>
< /table>
< /body>
< /html>
五. reply.php 回復留言提交頁面.
< ?
include("config.php");
$id = $_COOKIE["id"];
$sql = "select * from content";
header("content-Type: text/html; charset=utf-8");
$patch = $_POST["reply"];
$reply = str_replace("
","< br />",$patch);
$resule = mysql_query("UPDATE `2`.`content` SET `reply` = '$reply' WHERE `content`.`id` ="."$id");
echo "< script>alert('回復成功!');location.href='index.php';< /script>";
?>
這樣就可以建立出一個簡單的管理.管理帳號都是admin 因為只是判別輸入的是不是admin 是的話就把值輸入進session中.
㈢ 求用PHP寫一個簡單基本的留言板代碼,有點急
資料庫的創建
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>
㈣ php留言板的回復怎麼做
首先得設計好資料庫,留言一個表,回復一個表,然後把留言表中關鍵字ID關聯到回復表中。
比如:
留言表:message
id
contents
user
time
回復表:reply
id
m_id 關聯留言表中的id
contents
user
time
然後程序方面把對應的留言、回復保存到相應的表中,讀取的時候先遍歷留言表,然後通過留言表id再讀取對應的回復數據。
㈤ 用PHP怎麼做留言板
我來教你:
首先你要建立一個mysql資料庫
然後在資料庫裡面設置欄位 例如 用戶 留言
當你在html頁面的文本框填寫留言後,用表單點擊提交(在表單裡面要設置提交到那個頁面 比如:index.php)
當你提交到改頁面後,在這個頁面填寫你的php代碼
就是連接資料庫,然後將你的留言寫進資料庫
最後查看 和刪除 就是執行資料庫常見的查詢功能和刪除功能了
㈥ 用php中的文件做一個簡單的留言板。
如果你的空間支持動態網頁 也就是ASP JSP PHP中的一個的話就可以.如果只支持靜態網頁就不行.
貌似不行 不過恕我陋聞 也許使用別的技術也能達到你的目的
但我覺的你還是申請一個支持動態網頁的空間操作起來會比較簡單
㈦ php創建一個簡單留言板的問題Function name must be a string in D:\wamp\www\add.php on line 5
(1)$_post('submit') 應該寫成$_POST['submit'] 其他一樣改下
(2)echo $sql="insert into message (id,user,title,content,lastdate)" ." values ('','$_post(user)','$_post(title)','$_post(content)',now())"; 這個錯誤的用法,應該寫成
$sql="INSERTINTOmessage(id,user,title,content,lastdate)VALUES('','".$_POST['user']."','".$_POST['title']."','".$_POST['content']."',now())";
echo$sql;
㈧ 急求一個PHP的簡單的留言板,輸入臨時名字 然後輸入留言提交就可以顯示在頁面的
<?php
include 'conn.php'
$action = $_GET['action'];
$user=str_replace(" ","",$_POST[textfield]);
if($_POST['Submit2']){
if(!empty($_POST[textfield])){
$user=str_replace(" ","",$_POST[textfield]);
$password=str_replace(" ","",$_POST[textfield2]);
$user1=md5($user);
$password1=md5($password);
function userlogin($user1)
{
global $manager;
$sql="select * from $manager where user='$user1'";
//$sql="insert into manager (user,password) values ('$user','$password');";//用於插入需要的管理員用戶信息
$query=mysql_query($sql);
$row=mysql_fetch_array($query);
return $row;
}
$row=userlogin($user1);
if($row){
$ps=$password1==$row[password];
}else{
$ps=FALSE;
// echo "<script type="text/javascript">alert("用戶名錯誤")</script>";
}
if($ps){
$_SESSION[uid]=$user;
$_SESSION[upass]=$row[password];
header("Location:index.html");
}else{
$b=FALSE;
echo "<script type="text/javascript">alert("用戶名或者密碼錯誤")</script>";
echo '<script language="JavaScript">window.location.href="login.html";</script>'
}
}else{
echo "<script type="text/javascript">alert("用戶名不能為空格")</script>";
echo '<script language="JavaScript">window.location.href="login.html";</script>'
}
}
?>
以上是userlogin.php文件,其中引用的conn.php文件代碼如下:
其中資料庫自己建一個,注冊頁面大體也相同,你理解了這個,就自己能寫注冊頁面了
<?php
@header('Content-Type: text/html; charset=utf-8');
@session_start();
$conn = @ mysql_connect("127.0.0.1", "zznt", "19880210") or die("資料庫連接錯誤");
mysql_select_db("zznt", $conn);
//mysql_query("set NAMES 'utf8'");
//mysql_query("set character_set_client=utf8");
//mysql_query("set character_set_results=utf8");
mysql_query("set NAMES 'utf8'");
mysql_query("set character_set_client=utf8");
mysql_query("set character_set_results=utf8");
//$content=str_replace("'","鈥?,$content);
//htmlspecialchars();
?>
㈨ 用PHP完成留言板功能
留言表:留言ID、用戶ID、內容、發表時間、修改時間(此欄位可選)。
回復表:回復ID、留言ID、用戶ID、內容、發表時間、修改時間(此欄位可選)。
第一個用戶ID是誰發表的留言,第二個用戶ID是誰回復的留言,這樣無限回復沒問題,應該和你設計的差不多。
查詢(查詢某條留言的所有回復):
在回復表裡查詢所有該留言的回復記錄(查詢條件為留言ID),並按發表時間降序
回復內容表:
回復Id 回復內容
回復關聯表:
回復內容id 回復內容id
已私信
㈩ 關於php簡易留言板的一小段代碼..
我先給每行程序加上注釋
<?php
$name=$_POST['name'];//獲取表單提交過來的數據
$note=$_POST['note'];//同上
$db=new mysqli('localhost','root','123','dlw');//連接mysql資料庫並選擇dlw資料庫,很老的寫法了,不建議這么使用。
$sql="insert into gustbook values(name,time,words)";//sql語句
$sql=$sql.$name;//等同於sql .= $name 相當於讓上面那條sql語句後面連接$name但是這里在$name前面漏掉了一個( 應該是$sql = $sql."(".$name
$sql=$sql."',now(),'".$note."')";//同上
$result=$db->query($sql);//執行sql語句
echo"<center>write successfully.</center><br><br>";//輸出write successfully字元串,沒有任何意義,因為不管執行成不成功他都輸出。
?>
<html>
<body bgcolor="FFCCCC">
<center>
<a href="do.php">write again</a><br><br>
<a href="index.php">check out the message</a>
</center>
</body>
</html>
這應該是個很老的程序,你要用首先要改正幾個地方的寫法
1、$db=new mysqli('localhost','root','123','dlw');
最好寫成
mysql_connect('localhost','root','123');
mysql_slect_db('dlw');
2、 $sql="insert into gustbook values(name,time,words)";
$sql=$sql.$name;
$sql=$sql."',now(),'".$note."')";
可以寫一個sql語句就可以了,不用去連接,而且最好用標準的寫法。
$sql = "insert into gustbook (name,time,words) values ('".$name."',now(),'".$note."')";
3.$result=$db->query($sql);
echo"<center>write successfully.</center><br><br>";
加一個寫入成功的判斷
if(mysql_query($sql)){//注意這里不是$db因為我們前面把mysqli這個類已經省掉了。
echo"<center>write successfully.</center><br><br>";
}else{
"<center>write false.</center><br><br>";
}
具體留言不成功,可能還有幾個問題,首先你的資料庫有沒有這幾個欄位,還有具體有沒有連接成功資料庫,你可以用phpmyadmin看一看你的留言內容是不是已經寫入資料庫,如果有但沒顯示,那應該是讀取時候的問題,就不是你這個程序的問題了。
你用我給說的寫法試一下也不行嗎。
mysql_slect_db('dlw');
你確定資料庫連接成功了嗎,
把mysql_connect('localhost','root','123');改為
mysql_connect('localhost','root','123') or die("資料庫連接不成功");
如果數據沒有進去,那就跟index.php沒有任何關系,我看一下你現在的這個程序。表單還有添加的程序,還有數據表的結構。