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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.