删除php mysql不起作用

时间:2016-07-06 19:27:29

标签: php mysql sql-delete

您好,我对此没什么问题:

require_once("dbconnect.php");
mysql_query('set names utf8');

    $query = ('DELETE FROM `gallery` WHERE `id` = 16') or die("failed");

它不会从DB中删除记录。你能帮助我吗?谢谢。 dbconnect.php是正确的。

1 个答案:

答案 0 :(得分:2)

您所做的只是声明变量$query,但您没有运行它。您必须运行$query = mysql_query('DELETE FROM `gallery` WHERE `id` = 16')

编辑:话虽如此,请勿使用mysql_个功能。它们允许SQL注入,这非常危险。相反,最好使用

$mysqli = new mysqli(HOST, USERNAME, PASSWORD, DATABASE);
$query = $mysqli->query('DELETE FROM `gallery` WHERE `id` = 16');