php - HOW to relocation if a query doesnt exist -


if query exist http://localhost/page.php?pid=first-page open me, work, if write http://localhost/page.php?pid=second-page , second-page doesnt exist still open page , give error because doesnt find...

i understand why give me error, dont know how relocation url if write wrong query

session_start(); require "conx.php"; // determine page id use in our query below ---------------------------------------------------------------------------------------  if(isset($_get['pid'])){     $pageid = preg_replace('[^a-z0-9_]', '', $_get['pid']);     }        // $tag santized , ready database queries here // query body section proper page $stmt = $con->prepare('select pagebody pages linklabel = ?'); $stmt->bind_param('s', $pageid); $stmt->execute(); $result = $stmt->get_result(); while ($row = $result->fetch_array()) {     // $row     $body = $row["pagebody"];    } 

so how can relocation url address if query doesnt exist??

if goal redirect (relocation url address) user when result empty (the query doesn't exist), please try this:

//if query return empty result redirect user 404 page ! if(!$result->num_rows) {     header('location: /404.php'); //change page     exit; } 

i hope help.


Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -