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
Post a Comment