第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會有你想問的

帶有用戶 ID 變量的 MYSQL 的 HTTP 刪除請求

帶有用戶 ID 變量的 MYSQL 的 HTTP 刪除請求

PHP
Cats萌萌 2022-10-14 15:52:54
您好我正在嘗試使用 where 子句從 MYSQL 數(shù)據(jù)庫中的表中刪除記錄。這是我到目前為止所擁有的,但它不起作用,我不知道該怎么做。有沒有辦法使這項(xiàng)工作?我已經(jīng)包含了我的刪除方法和 php 文件代碼。我的網(wǎng)址 - deleteCompletedGoal=("http://10.0.2.2/deleteCompletedGoalAddress.php?user_goal_id="+completed_goalID);我的代碼 - private void deleteNonActiveGoal(){        try {            URL url = new URL(deleteCompletedGoal);            HttpURLConnection http = (HttpURLConnection) url.openConnection();            http.setRequestMethod("POST");            http.setRequestProperty("X-HTTP-Method-Override", "DELETE");            http.setDoInput(true);            http.setDoOutput(true);            OutputStream ops = http.getOutputStream();            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(ops, "UTF-8"));            String data = URLEncoder.encode("user_goal_id", "UTF-8") + "=" + URLEncoder.encode(completed_goalID, "UTF-8") + "&&";            writer.write(data);            writer.flush();            writer.close();            ops.close();            InputStream ips = http.getInputStream();            BufferedReader reader = new BufferedReader(new InputStreamReader(ips, "ISO-8859-1"));            String line;            while ((line = reader.readLine()) != null) {                result += line;            }            reader.close();            ips.close();            http.disconnect();        }        catch (MalformedURLException e) {            result = e.getMessage();        } catch (IOException e) {            result = e.getMessage();        }    }PHP 文件:<?phprequire "connection.php";$completed_goalID=$_POST["user_goal_id"];$mysql_qry = "DELETE from user_goals WHERE user_goal_id ='$completed_goalID'";if($conn->query($mysql_qry) === TRUE) {echo "delete successful";}else{echo "delete failed";}$conn->close();?>
查看完整描述

2 回答

?
阿波羅的戰(zhàn)車

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超6個(gè)贊

由于您在查詢字符串中發(fā)送變量,因此您將使用 GET 而不是 POST。改變:

 $completed_goalID=$_POST["user_goal_id"];

$completed_goalID=$_GET["user_goal_id"];

警告

Little Bobby您的腳本面臨 SQL 注入攻擊的風(fēng)險(xiǎn)。了解MySQLi的預(yù)處理語句。即使轉(zhuǎn)義字符串也不安全!


查看完整回答
反對 回復(fù) 2022-10-14
?
慕森王

TA貢獻(xiàn)1777條經(jīng)驗(yàn) 獲得超3個(gè)贊

使用 $_GET 獲取來自 url 的變量,例如:

$completed_goalID=$_GET["user_goal_id"];

更改查詢以防止 sql 攻擊(參考),例如:

 <?php

    require "connection.php";


    $completed_goalID=$_POST["user_goal_id"];



    $mysql_qry = $conn->prepare("DELETE from user_goals WHERE user_goal_id=?");

    $mysql_qry->bind_param('i',$completed_goalID);

    if($mysql_qry->execute() === TRUE){


    echo "delete successful";

    }

    else{

    echo "delete failed";

    }

   $mysql_qry->close();

    $conn->close();

    ?>


查看完整回答
反對 回復(fù) 2022-10-14
  • 2 回答
  • 0 關(guān)注
  • 115 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號