mysqli - PHP - redirecting to other page if there are no results -


i redirect user other page if there no results.

what meant is, passing variables via url , using on second page , if the variables empty able redirect page.

however when user changes variable id in url

index.php?product-tit/=how+to+deal+with%20&%20item-id-pr=15

to index.php?product-tit/=how+to+%20&%20item-id-pr=

nothing displayed on page there way can redirect other page in above condition?

$title = urldecode($_get['product-tit/']); $id = $_get['item-id-pr']; $mydb = new mysqli('localhost', 'root', '', 'database');  if(empty($title) && empty($_get['item-id-pr'])){ header('location: products.php'); } else{ $stmt = $mydb->prepare("select * products title = ? , id = ? limit 1 "); $stmt->bind_param('ss', $title, $id); $stmt->execute(); ?>  <div> <?php $result = $stmt->get_result();  while ($row = $result->fetch_assoc()) { echo wordwrap($row['price'], 15, "<br />\n", true);  } $mydb->close ();} ?> </div> 

your condition requires both variables empty, if want redirect when empty should use or (||):

if(empty($title) || empty($_get['item-id-pr'])){   header('location: products.php');   // make sure nothing more gets executed   exit(); } 

also note cannot output browser before header statement.


Comments

Popular posts from this blog

ios - UICollectionView Self Sizing Cells with Auto Layout -

node.js - ldapjs - write after end error -

DOM Manipulation in Wordpress (and elsewhere) using php -