FUNKAM35 Posted March 1, 2013 Share Posted March 1, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/275083-redirect-when-row-been-deleted/ Share on other sites More sharing options...
trq Posted March 1, 2013 Share Posted March 1, 2013 Assuming $result is a mysqli result object; if (!$result->num_rows) { header('Location: http://somedomain.com'); } Quote Link to comment https://forums.phpfreaks.com/topic/275083-redirect-when-row-been-deleted/#findComment-1415787 Share on other sites More sharing options...
Christian F. Posted March 1, 2013 Share Posted March 1, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/275083-redirect-when-row-been-deleted/#findComment-1415788 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.