简体   繁体   中英

php mysqli prepared statement remove query issue

I have made a page to remove different elements of my site, but for some reason it's not working... Event though i set the fMenu to be i - integer, because it is. When i run the code below, it gives me:

Fatal error : Call to a member function bind_param() on a non-object in C:\\Users\\joonas\\Desktop\\Le Kerouac\\root\\admin\\remove.php on line 44

Code(PHP):

include_once('../php/connDbPrepared.php');
mysqli_set_charset($mysqli, 'utf8');
//Anti mysql injection precautions
$menu = mysqli_real_escape_string($mysqli, $menu);
$sql = "REMOVE FROM menu WHERE fMenu = ?";
$stmt = $mysqli->prepare($sql);
$stmt->bind_param("i", $menu);
if($stmt->execute())
{
    $stmt->close();
    echo '
    <script type="text/javascript">
    window.location.replace("../admin/admintable.php?page=main&message=removeSuccessMenu");
    </script>
    ';
}
else
{
    echo '
    <script type="text/javascript">
    $(document).ready(function()
    {
        $("#screenCover").slideToggle("slow");
        $("#closePopup").click(function()
        {
            $("#screenCover").slideToggle("slow");
            setTimeout(resetPage, 600);
        });
});
function resetPage()
{
    window.location.replace("../admin/admintable.php?page=main");
}
</script>
<div id="screenCover" style="display:none;">
<div id="popup">
<div id="closePopupMain">
<p id="closePopup"><a href="#">X</a></p>
</div>
<p id="failure">Le menu n\'a pas éte enlevée! Cause: Erreur '.mysqli_errno($mysqli).": ".mysqli_error($mysqli).'</p>
</div>
</div>';
}

mysql中没有REMOVE关键字,请使用DELETE:

Delete from menu where fmenu = ?

The correct function name is bindParam() not bind_param()

Change

$stmt->bind_param("i", $menu);

to

$stmt->bindParam("i", $menu);

This will get rid of the error message that you are getting. Then you need to fix your SQL statement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM