日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

PHP+SQlite 制作简单的留言板

發布時間:2023/12/16 php 35 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP+SQlite 制作简单的留言板 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
? SQLite,是一款輕型的數據庫,是遵守ACID的關聯式 數據庫管理系統 ,它的設計目標是嵌入式的,而且目前已經在很多嵌入式產品中使用了它,它占用資源非常的低,在嵌入式設備中,可能只需要幾百K的內存就夠了。它能夠支持Windows/Linux/Unix等等主流的 操作系統 ,同時能夠跟很多程序語言相結合,比如 Tcl、C#、PHP、Java等,還有ODBC接口,同樣比起Mysql、PostgreSQL這兩款開源世界著名的數據庫管理系統來講,它的處理速度比他們都快。SQLite第一個 Alpha版本 誕生于2000年5月。 至今已經有12個年頭,SQLite也迎來了一個版本 SQLite 3已經發布。 ??? ? SQLite數據庫和mysql的用法差不多,要下昂使用? SQLite 先開啟php_sqlite 和 php_pdo_sqlite ,開啟方法如下如果你是wamp點開wanp找到php然后點擊php擴展,把里面的php_sqlite 和 php_pdo_sqlite?前面打勾。或者你在php.ini里面配置去掉php_sqlite 和 php_pdo_sqlite?前面的; ? ? ? 建立sqlite數據庫這里就不說了,很簡單,在wamp下的sqlitemanager就可以以可視化的方式建立數據庫,用法和mysql一樣 ? ? ? 留言板制作如下: index.php是留言頁面 <!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=gbk" /> <title>無標題文檔</title> </head>
<body>
<?php $db = sqlite_open("liuyanban.db",0666,$sqlite_error); if($_POST['sub']=="提交"){ ?? $sql = "insert into liuyan (id,title,content,time) values (NULL,'$_POST[title]','$_POST[content]','$_POST[time]')"; ?? ?? if(sqlite_query($db,$sql)){ ? // 和 mysql_query 參數不同 ?? echo "<script>alert('添加成功');</script>"; ?? echo "<meta http-equiv=refresh content='0;url=index.php'>"; ?? ?? }else{ ?? echo "<script>alert('添加失敗');history.back();</script>"; ?? } } ?>


<?php include_once("head.html"); ?> <form action="" method="post"> 標題:<input type="text" size="40" name="title" /><br /> 內容:<textarea name="content" cols="70" rows="7"></textarea><br /> 時間:<input type="text" name="time" value="<?php echo date('Y-m-d H:i:s',time());?>" size="40"/> <input type="submit" name="sub" value="提交" /> ?<input type="reset" value="重置" name="res" /> </form> </body> </html> view.php是查看留言頁面 <!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=gbk" /> <title>無標題文檔</title> </head>
<body> <?php include_once("head.html"); ?> <?php $db = sqlite_open("liuyanban.db",0666,$sqlite_error); ?$sql = "select * from liuyan order by id DESC"; ?$query = sqlite_query($db,$sql); ?while($result = sqlite_fetch_array($query)) ?{ ?echo "標題:".$result['title']."<br>"; ?echo "內容:".$result['content']."<br>"; ?echo "時間:".$result['time']."<br>"; ??> <a href="deal.php?id=<?php echo $result['id'];?>&deal=delete">刪除</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <a href="update.php?id=<?php echo $result['id'];?>">修改</a> <hr size="2" /> <?php } ?> </body> </html> deal.php是實現留言的刪除與修改 <?php? $db = sqlite_open("liuyanban.db",0666,$sqlite_error); $id=$_GET['id']; $deal=$_GET['deal']; if($deal=="delete"){ ?? $sql = "delete from liuyan where id = '$id'"; ?? if(sqlite_query($db,$sql)){ ??echo "<script>alert('刪除成功');</script>"; ??echo "<meta http-equiv=refresh content='0;url=view.php'>"; ? ? ? ? ? ? ?? ?? }else{ ?? echo "<script>alert('刪除失敗');history.back();</script>"; ?? } } if($deal=="update"){ ?? $sql = "update liuyan set title = '$_POST[title]',content = '$_POST[content]',time = '$_POST[time]' where id = '$id'"; ?? if(sqlite_query($db,$sql)){ ??echo "<script>alert('修改成功');</script>"; ??echo "<meta http-equiv=refresh content='0;url=view.php'>"; ? ? ? ? ? ? ?? ?? }else{ ?? echo "<script>alert('修改失敗');history.back();</script>"; ?? } } ?> update.php是修改留言頁面 <!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=gbk" /> <title>無標題文檔</title> </head>
<body> <?php $id = $_GET['id']; $db = sqlite_open("liuyanban.db",0666,$sqlite_error); ?$sql = "select * from liuyan where id = '$id'"; ?$query = sqlite_query($db,$sql); ?$result = sqlite_fetch_array($query); ?> <form action="deal.php?id=<?php echo $id;?>&deal=update" method="post"> 標題:<input type="text" size="40" name="title" value="<?php echo $result['title'];?>" /><br /> 內容:<textarea name="content" cols="70" rows="7"><?php echo $result['content'];?></textarea><br /> 時間:<input type="text" name="time" value="<?php echo $result['time'];?>" size="40"/> <input type="submit" name="sub" value="提交" /> ?<input type="reset" value="重置" name="res" /> </form> </body> </html> head.html是頭部 <!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=gbk" /> <title>無標題文檔</title> </head>
<body> <a href="index.php">添加留言</a> | <a href="view.php">查看留言</a> <hr size="1" /> </body> </html> 該代碼經過測試可以正常運行

總結

以上是生活随笔為你收集整理的PHP+SQlite 制作简单的留言板的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。