删除产品Mysqli

时间:2015-01-02 23:11:29

标签: php mysql mysqli

该网站运作正常,但网站上有旧代码。 所以它一直显示MySql被删除。我决定将其转移到MySqli。我差不多一半,但删除部分一直给我一个错误:

Warning: mysqli_query() expects at least 2 parameters, 1 given
Warning: mysqli_error() expects exactly 1 parameter, 0 given

错误指向以下代码:

// delete the entry
$result = mysqli_query($sql)
or die(mysqli_error()); 

?>

<script>alert("Successfully Deleted!"); 
    window.location.href='<?php echo $location;?>';
 </script>

注意:

$sql = "DELETE FROM jj1 WHERE id=$id";

1 个答案:

答案 0 :(得分:0)

您必须将连接资源/链接作为第一个参数(您指定的变量mysqli_connect)传入。请参阅documentation for mysqli_query

$sql = "DELETE FROM jj1 WHERE id=$id";
mysqli_query($connection, $sql);

附注:您应该escape放入SQL查询或使用prepared statements的任何变量。