![](/img/trans.png)
[英]DELETE FROM table WHERE ID='$id' — Variable refuses to stick
[英]Delete from table where id in (*php variable*) returns error
我在php應用程序中工作,在該應用程序中我必須從列表中刪除選定的項目,其中每個項目都有自己的mysql數據庫ID,一切正常,直到在php中執行查詢為止。
這是錯誤消息:
您的SQL語法有誤; 檢查與您的MySQL服務器版本相對應的手冊以獲取在第5行的''附近使用的正確語法
這是我在查詢中執行的字符串:
$queryDE = "delete from md5_agenda
where id_empresa = $empi
and id_unidade = $unii
and id_usuario = $usrr
and id_item_agenda in ($deletar);"
變量$deletar
從post方法接收其值,其值類似於: 35,36,47,...
並且可以是一個或多個不同的值
但是我的問題是,如果我將$deletar
更改為確切的值,一切都會正常進行,但是,如果我將php變量與“完全相同”的值一起使用,它將無法正常工作並返回上一個錯誤消息,那么我就不知道該做什么...我想保持這種方式,在這里我可以選擇要刪除的所有ID,而無需重復查詢。
謝謝。
編輯:
foreach($deletar as $val)
{
$queryDE = "delete from md5_agenda
where id_empresa = $empi
and id_unidade = $unii
and id_usuario = $usrr
and id_item_agenda = $val;"
}
your code is not working because $deleter is return multiple value.
check code it's working.
為什么不使用安全的參數化查詢?
$db =new PDO('... your connection string ... ');
$stmt = $db->prepare("delete from md5_agenda
where id_empresa = :empi
and id_unidade = :unii
and id_usuario = :usrr
and id_item_agenda in (:deletar);");
$stmt->execute(array(
':empi' => $empi,
':unii' => $unii,
':usrr' => $usrr,
':deletar' => $deletar
)
);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.