本篇內(nèi)容介紹了“php如何實(shí)現(xiàn)留言板刪除功能”的有關(guān)知識(shí),在實(shí)際案例的操作過(guò)程中,不少人都會(huì)遇到這樣的困境,接下來(lái)就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細(xì)閱讀,能夠?qū)W有所成!
成都創(chuàng)新互聯(lián)公司專注于隆德企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站設(shè)計(jì),商城網(wǎng)站建設(shè)。隆德網(wǎng)站建設(shè)公司,為隆德等地區(qū)提供建站服務(wù)。全流程按需定制設(shè)計(jì),專業(yè)設(shè)計(jì),全程項(xiàng)目跟蹤,成都創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
php實(shí)現(xiàn)留言板刪除功能的方法:1、創(chuàng)建update.php文件;2、通過(guò)“public function delete(){require_once 'config.inc.php'...}”方法實(shí)現(xiàn)留言板刪除功能即可。
本文操作環(huán)境:Windows7系統(tǒng)、PHP7.1版、DELL G3電腦
php怎么實(shí)現(xiàn)留言板刪除功能?
PHP實(shí)現(xiàn)小程序留言板功能 之 只能修改刪除自己發(fā)表的留言
PHP實(shí)現(xiàn)小程序留言板功能
這里我實(shí)現(xiàn)了一個(gè)只能修改和刪除自己的留言,如下圖所示
這是接上篇文章做的添加了新功能,我也不多廢話了,發(fā)修改了和添加的代碼
logs.wxml
<form bindsubmit="liuyanban"> <view style="float:left;margin-left:15rpx">留言內(nèi)容:</view> <input type="text" name="content" style="border:1px solid #ccc"></input> <button form-type="submit">提交留言</button> </form> <view wx:for="{{liuyantext}}" wx:key="{{liuyantext}}"> <view style="margin-top:15rpx;">用戶名:{{item.uname}}</view> <view style="">內(nèi)容:{{item.content}}</view> <navigator wx:if="{{uids == item.uid}}" style="float:left;margin-right:30rpx;color:#0000FF" url="/pages/update/update?id={{item.id}}">修改</navigator> <view wx:if="{{uids == item.uid}}" bindtap="deletei" style="margin-button:30rpx;color:#0000FF" src="{{item.id}}">刪除</view> </view>
logs.js
Page({ data: { }, /** * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載---獲取從其他頁(yè)面?zhèn)鱽?lái)的值經(jīng)行接收 */ onLoad: function(options) { this.setData({ id:options.id, uid: options.uid, uname: options.uname }) var that = this that.setData({ uids:that.data.uid }) wx.request({ url: 'http://127.0.0.1/liuyanban.php', data:{ 'a':1 }, header: { 'content-type': 'application/json'}, method: 'GET', dataType: 'json', success: function(res) { that.setData({ liuyantext: res.data['0'], }) console.log('查詢值', res.data['0']) }, }) }, liuyanban: function(e) { if(e.detail.value.content != ""){ var that = this wx.request({ url: 'http://127.0.0.1/liuyanban.php', data: { "uid":this.data.uid, "uname":this.data.uname, "content":e.detail.value.content }, header: { 'content-type': 'application/x-www-form-urlencoded'}, method: 'POST', dataType: 'json', success: function(res) { console.log('插入數(shù)據(jù)值:',res) }, }) } console.log('留言內(nèi)容',e.detail.value.content) console.log('uid:', this.data.uid) console.log('uname:', this.data.uname) }, deletei: function (e) { wx.showModal({ title: '提示', content: '是否確定刪除', success(res) { if (res.confirm) { wx.request({ url: 'http://127.0.0.1/update.php', method:"get", header: { 'content-type': 'application/json'}, dataType:'json', data:{ 'a':2, 'id': e.currentTarget.dataset.src }, success:function(){ wx.showToast({ title: '刪除成功', icon: 'none', }) } }) console.log('用戶點(diǎn)擊確定') } else if (res.cancel) { console.log('用戶點(diǎn)擊取消') } } }) }, })
這里我說(shuō)一下,上篇文章的查詢留言發(fā)表留言PHP沒(méi)有變,多添加了一個(gè)修改頁(yè)面和一個(gè)PHP文件,修改頁(yè)面如下圖所示
然后就是修改頁(yè)面和PHP,刪除放到了發(fā)表留言頁(yè)面但是后臺(tái)文件是鏈接到修改頁(yè)面的
update.wxml
<form bindsubmit="update"> <view wx:for="{{updatei}}" wx:key="{{updatei}}"> <view style="float:left">內(nèi)容:</view> <input style="border:1px solid #ccc" type="text" value="{{item}}" name="content"></input> </view> <button form-type="submit">修改</button> </form>
update.js
Page({ data: { }, onLoad: function (options) { this.setData({ id: options.id, }) var that = this wx.request({ url: 'http://127.0.0.1/update.php', data: { 'a': 1, 'id':that.data.id }, header: { 'content-type': 'application/json' }, method: 'GET', dataType: 'json', success: function (res) { that.setData({ updatei: res.data, }) console.log('查詢值',res.data) }, }) }, update:function(e){ wx.showToast({ title: '修改成功', icon: 'none', }) wx.request({ url: 'http://127.0.0.1/update.php', method: "GET", header: { 'content-type': 'application/json' }, data:{ "id":this.data.id, "content":e.detail.value.content }, dataType:'json', success:function(res){ wx.navigateBack({ delta: 1 }) } }) console.log('content',e.detail.value.content) }, })
update.php
<?php class update{ //查詢 public function select(){ require_once 'config.inc.php'; $sql = "select * from wt_blog where id = ?"; try{ $stmt = $link -> prepare($sql); $stmt -> execute([$_GET['id']]); $row = $stmt->fetch(PDO::FETCH_ASSOC); //要轉(zhuǎn)成json格式給小程序才可以 echo json_encode([$row['content']]); }catch(PDOException $e){ die($e->getMessage()); } } //修改 public function edit(){ require_once 'config.inc.php'; $sql = "update wt_blog set content = ? where id = ?"; try{ $stmt = $link -> prepare($sql); $stmt -> execute([$_GET['content'],$_GET['id']]); }catch(PDOException $e){ die($e->getMessage()); } } //刪除 public function delete(){ require_once 'config.inc.php'; $sql = 'delete from wt_blog where id=?'; try{ $stmt = $link -> prepare($sql); $stmt -> execute([$_GET['id']]); }catch(PDOException $e){ die($e->getMessage()); } } } $a = new update(); if($_GET['a'] == 1){ $a->select(); }elseif($_GET['a'] == 2){ $a->delete(); }else{ $a->edit(); } ?>
“php如何實(shí)現(xiàn)留言板刪除功能”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識(shí)可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實(shí)用文章!
新聞名稱:php如何實(shí)現(xiàn)留言板刪除功能
鏈接分享:http://www.chinadenli.net/article2/ieooic.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站制作、做網(wǎng)站、動(dòng)態(tài)網(wǎng)站、網(wǎng)站建設(shè)、企業(yè)網(wǎng)站制作、
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)