我試着用這個URL來刪除數據庫中的東西:通過url查詢從mysql中刪除。錯誤「的查詢是空的」
siteurl.com/mail.php?action=delete&mail_id=10
與此代碼:
if ($action == delete) {
if(isset($_GET['id'])) {
$deleteid = $_GET['id'];
$sql = "DELETE FROM mail WHERE mail_id = ".$deleteid." LIMIT 1";
$query = mysql_query($sql);
header('Location: '.$_SERVER['HTTP_REFERER'].' ');
exit();
}
}
但它不工作,它顯示錯誤:Query was empty
怎麼了?
我相信你在這裏得到一個錯字:: $ deleteid = $ _GET ['mail_id']; – s3polz
$ action = $ _GET ['action']; $ deteleid = $ _GET ['mail_id']; if($ action ==「delete」) – thomasbabuj
另外,除非你用define('delete','delete')設置一個常量,否則GET方法提交的任何值實際上都是一個字符串,它需要被封裝引號(除非數字)像'if($ _ GET ['action'] =='delete'){}' – inhan