php+ajax實現無重新整理的新聞留言系統(附源碼)_PHP教程

來源:互聯網
上載者:User
ajax自從有了jquery就非常的簡單容易實現了,下面我來介紹一款基於jquery ajax+php mysql的無重新整理的新聞留言系統實現過程,希望本文章能給您帶來協助。

最簡明易懂的一個ajax無重新整理留言系統了,源碼中省略了接受資料驗證的過程。讀者可根據自己的需求進行擴充。


核心源碼:


1.設定檔:config.php

代碼如下 複製代碼


//資料庫配置資訊(使用者名稱,密碼,資料庫名,表首碼等)

$cfg_dbhost = "localhost";

$cfg_dbuser = "root";

$cfg_dbpwd = "root";

$cfg_dbname = "ajaxdemo1";

$cfg_dbprefix = "";


$link = mysql_connect($cfg_dbhost,$cfg_dbuser,$cfg_dbpwd);

mysql_select_db($cfg_dbname);

mysql_query("set names utf8");

?>

2.處理請求:deal.php

代碼如下 複製代碼


header("Content-type:text/html;charset=utf-8");

include "config.php";

//post接收資料,只是示範效果,這裡就省去驗證了

$name = $_POST['name'];

$content = $_POST['content'];


$sql = "insert into test (name,content) values ('{$name}','{$content}');";

$res = mysql_query($sql,$link);

if($res){

echo '{"name": "'.$name.'","content": "'.$content.'","status": "1"}';

}

?>

3.首頁代碼:index.php

代碼如下 複製代碼

無重新整理


include "config.php";

$sql = "select * from test;";

$res = mysql_query($sql,$link);

while($row=mysql_fetch_array($res)){

echo "

".$row['name']." 發表了:".$row['content']."

";

}

?>

資料庫檔案

代碼如下 複製代碼


DROP TABLE IF EXISTS `test`;
CREATE TABLE `test` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(64) NOT NULL,
`content` text NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

源碼下載地址:php+ajax實現無重新整理的新聞留言系統下載

http://www.bkjia.com/PHPjc/632619.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/632619.htmlTechArticleajax自從有了jquery就非常的簡單容易實現了,下面我來介紹一款基於jquery ajax+php mysql的無重新整理的新聞留言系統實現過程,希望本文章能給您帶...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.