導航:首頁 > 編程語言 > 簡單phpmysql留言

簡單phpmysql留言

發布時間:2022-07-23 02:24:35

php+mysql留言板發布文章問題

我會再建一個用戶表,用戶表欄位包括:id,username, age, grade(用戶等級)。。。
然後在文章表中添加一個欄位 uid 用來存發表文章的用戶的id。

一個用戶能夠發表多篇文章,用關系型資料庫mysql模擬就是這樣。是一對多的關系。一個用戶對應多篇文章。在文章表中保存用戶id便可。

查詢的時候連表查詢(使用 join 關鍵字),便可,比如:
select i_title, i_content , username from articleTable as a join userTable as u on a.uid = u.id ;

其中的 userTable as u 是給表起別名,方便sql語句其他地方調用,不用寫那麼長的表名。

Ⅱ PHP APA MYSQL製作一個簡單的留言板

不多說,直接給你貼地址:
http://www.codepub.com/software/view-software-15539.html
http://www.codedn.com/view/2359.html
這個網上很多,如果以上不滿意,可以自己選擇比較合適的:
http://www.google.cn/search?hl=zh-CN&client=pub-2918997108407961&prog=aff&newwindow=1&q=php%E7%95%99%E8%A8%80%E6%9C%AC+%E6%BA%90%E7%A0%81&btnG=Google+%E6%90%9C%E7%B4%A2&aq=f&oq=
留言本其實很簡單,建議自己寫一個,很容易。如果樓主是php愛好者,可以加入我們團。我們定期做一些技術專題。

Ⅲ 用php,mysql製作留言板

你的程序一開始就已經require deal.php了,不明白為什麼form裡面的action還是指向deal.php,把那個action='',自然就可以了。

Ⅳ php與mysql寫留言板的原理

1.讀庫,取數據信息做顯示列表(登錄和非登錄都可以看到)
2.登錄發表,你留言板 資料庫裡面要有一個欄位對應用戶的id,暫稱為user_id,A用戶,發表了3條信息,你取數據的時候,跟上當前用戶的user_id,當然 在用戶登錄後,你要生成用戶cookie 或者session,這樣才能得到當前是那個用戶登錄的。

Ⅳ PHP+mysql做一個留言板

先select 你的留言板 內容 送入數組 result
然後循環for($i=0;$i<count($result);$i++){$result[$i]['question_no'] = $i+1;} 然後前台調foreach循環的 question_no 只有思路 具體你要自己寫

第二個問題 問錯了 如果循環對的話 和 div 對應的話 不會出錯的 你要自己檢查你是否寫對沒

Ⅵ php+MySQL實現簡單留言、修改、刪除功能,遇到問題!

$sql = "DELETE FROM gbook WHERE id = '$id' ";
原因:1關了全局變數後,register_globals = Off 傳遞的參數在接收時就得用$_POST或者是$_GET或是$_REQUEST了
2依據你的情況,$sql = "DELETE FROM gbook WHERE id = '".$_GET['id']."'";
試試這樣是否可以,另外,其實在接收參數的時候,在使用前最好做些安全過濾,不然不安全,不過,做為練慣用,倒是無防,希望可以幫到你

Ⅶ PHP+mysql寫一個留言板

在留言表單插入表單插入代碼mysql:資料庫的用戶名是:root 密碼:123456

:<?php
$conn=mysql_connect("localhost","登陸mysql資料庫的用戶名","登陸mysql資料庫的密碼");//建立資料庫連接資源
if(!$conn) echo"資料庫連接有誤";//判斷資料庫連接是否有誤
mysql_query("set names'gbk'");設置中文顯示防止亂碼出現
mysql_select_db('連接的資料庫名
',$conn);//連接的資料庫名
$sql="INSERT INTO `liuyan`.`use_info` (
`name` ,
`sex` ,
`text`
)
VALUES (
'$name', '$sex', '$text'
)";//想liuyan這資料庫寫入數據
mysql_query($sql);//讓sql語句執行
mysql_close;//關閉連接節省機子內存
?>
讓留言的內容在指定頁面顯示大體和上面的語句差不多:<?php $conn=mysql_connect('localhost','用戶登陸資料庫的用戶名','登陸資料庫的密碼');
if(!$conn) echo '資料庫連接有誤';//判斷資料庫的連接是否有誤
mysql_select_db('liuyan',$conn);//資料庫的選擇
mysql_query("SET NAMES 'GBK'");//設置資料庫中文的顯示
$sql="select * from use_info"; //要鏈接的目標資料庫
$result=mysql_query($sql);//讓sql語句執行
/*$rs=mysql_fetch_array($result) //將資料庫的內容保存的數組變數中*/
while($rs=mysql_fetch_array($result))
{
echo $rs['name']."".$rs['sex']."".$rs['text'].""."</br>";
}//循環顯示數組內容
mysql_close;//資料庫的關閉

?>

Ⅷ php+mysql 一篇文章對應多個留言..怎麼做

建2個表,
一個是文章表,數據結構為:
id,文章標題,文章內容,上傳時間,上傳人,留言數量。

一個是留言表,數據結構為:
id,文章id,留言標題 ,留言內容,留言時間,留言人。

兩個表的id是自增的,是一個唯一的識別記錄的標記,留言表中「文章id」則對應於文章表中「id」,這樣通過「文章id」就可以關聯到文章表的文章。

Ⅸ 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中.

閱讀全文

與簡單phpmysql留言相關的資料

熱點內容
如何刪掉多餘的伺服器 瀏覽:220
c編程演算法 瀏覽:833
堵車如何緩解壓力 瀏覽:17
喜鵲快貸app怎麼了 瀏覽:263
海龜編輯器積木編程怎麼安裝 瀏覽:185
程序員理發店生意怎麼樣 瀏覽:603
程序員羅技 瀏覽:180
軟考初級程序員課程2021下載 瀏覽:491
杭州程序員奶奶 瀏覽:880
不聽命令造成錯誤 瀏覽:981
kool系統源碼 瀏覽:610
流氓app在哪裡看 瀏覽:98
域名購買了怎麼指向伺服器 瀏覽:121
安卓手機如何讓照片顏色反轉 瀏覽:859
怎麼下載卓睿安手機版 瀏覽:514
h3crange命令 瀏覽:468
php前景和python 瀏覽:338
php壓縮圖片內存大小 瀏覽:495
在哪裡可以查看雲伺服器的信息 瀏覽:70
python讀取非txt文件 瀏覽:799