I am trying to delete a row using a href, it’s not showing the error but it’s not delete the row from my table either. Not sure what i’m doing wrong.
delete.php require_once "db.php"; $id = $_GET['id']; $sql = "DELETE FROM books WHERE isbn = ". $id; if (mysqli_query($db, $sql)){ echo "Success"; }else{ echo "Error"; }
main.php if($resultSet->num_rows > 0){ while($rows = $resultSet->fetch_assoc()){ $au = $rows['author']; $bt = $rows['booktitle']; $rev = $rows['reserved']; echo"<tr><td>$au</td><td>$bt</td><td>$rev</td><td><a href='delete.php?id=".$rows['isbn']."'>Delete</a></td></tr>n"; } echo"</table>"; }
Advertisement
Answer
It seems like if you’re getting the success message then the query ran successfully, which means that the database connection established OK so we can rule that out.
I think that your query is running but not finding any match on the ISBN so the record isn’t getting deleted. I would try echoing out the actual SQL query just before execution so you can then copy it, connect to the database and then paste that query in to run yourself. Maybe change it to a SELECT statement first so you can see if it actually gets the row for deletion. If not then a row with that ISBN either doesn’t exist or you’ve got something strange like an extraneous space/other weird character in the ID somewhere.