Mysqli Delete not working

Hey,

I’m having some issues with “Delete” option of CRUD. My Insert, View, and update work great, just the delete portion is giving me trouble.

$id = $_GET['cid'];
$results = $conn->query("DELETE FROM customer_registration WHERE cid='$id'");

if($results){
    print 'Success!'; 
}else{
    print 'Error : ('. $conn->errno .') '. $mysqli->error;
}

then for the link to delete I have this:

<a href = "delete.php?cid=<?php echo $id ?>"onclick="return confirm('Are you sure you want to delete?')">Delete Contractor</a>

Normally I’ve never had an issue with deleting rows out of databases until now, this has me stumped. So when I click on the link, it doesn’t do anything, no errors, just dead.

please let me know if you need to see the site to accommodate this. I currently only have local version of it.

Thanks,

When you hover over the link, does the value of cid show what you would expect? Does it actually call the delete.php script, and if so, what is the value of $id when it gets there?

if you can see in the purple. this is what I get when I hover over the “delete link”

Does a record with the specified id actually exist to be deleted?

What happens if you change the id in the address bar and then resubmit the page - can you delete any of the other rows in the table by updating the address for the delete page?

I can view other entries. I can only delete entries if If erase update and replace it with delete.

No closing semi-colon after the javascript onclick statement?

semicolons are optional in JavaScript - even poorly written antiquated JavaScript jumbled with HTML is allowed to omit it.

Oh OK. I was going to mention no semi-colon after the php echo, but that’s obviously working as the link looks OK.

Some kind of permissions check being in the admin folder?

can you elaborate a bit more? I don’t have an .htacess yet if that’s what you’re referring to.

I wasn’t necessarily thinking of htaccess

If you don’t have any known access controls in place (that might have become broken), it might be that they got changed somehow unbeknownst to you. (eg. if you rearranged / renamed things)

Not per se related to your question, but I would like to add that you should never use string concatenation to build queries - you risk SQL injection this way. Please use prepared statements with bound variables as explained here.

So is it actually calling delete.php which is then failing to perform the delete, or is it failing to call delete.php? Does delete.php actually start running?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.