Jump to content

Redirect when row been deleted


FUNKAM35

Recommended Posts

I need to redirect a page only when the bike_id no longer exists

 

as at the minute if the bike_id has been deleted from the databse it shows the page but without info.

Of course, if the bike:id is still in the databsae I need it to remain as it is:

$bike_id = $_GET['bike_id'];
$select = "SELECT * FROM bike_sale WHERE bike_id='$bike_id' ";

so how do i put, if bike_id no longer found redirect to home `page

thanks

Link to comment
https://forums.phpfreaks.com/topic/275083-redirect-when-row-been-deleted/
Share on other sites

First off: Your code is wide open for SQL injections, you need to secure this ASAP.

I recommend going with MySQLI or PDO (if you're not already), and use Prepared Statements to secure your input. You also want to validate the input for most thing, but in the case of an ID from an URL the act of retrieving the record is validation in and of itself.

 

That said, the answer to your question is simple: Get the count of how many rows were retrieved, and use an if to check what course of action to use.

I would generally recommend showing a warning message on (or instead of) the warning page, not redirecting the user to the home page. That way a user knows exactly what the status is, and can go back to the page himself if need be.

 

If you still insist upon the redirect, then header is the function you're after. Just remember to call die after it, to ensure that the script stops parsing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.