Hello. Is it possible to use a select statement as if it dont fetch any row then it will be redirect to some other page? For expamle a mysql statement: mysql_query("select somecolumn from sometable where someid='$id' ") or die ("no $id is found in someid field"); this statement will show the die msg when it dont found any match. But I dont want to use die rather redirect to some other page in such cases (where 'where clause' dont match). Can it be done? Thanks.
$query = mysql_query("select somecolumn from sometable where someid='$id'"); if (!$query) { header("Location: file.php?do=mainpage"); exit(); } else { // Blah } That is one way, the other way is to $query = mysql_query("select somecolumn from sometable where someid='$id'"); if (!$query) { echo "<meta http-equiv=\"refresh\" content=\"0;URL=http://site.com\" />"; exit(); } else { // Blah }
This also works.. I think. mysql_query("select somecolumn from sometable where someid='$id' ") or header("Location: file.php?do=mainpage"); PHP:
Having difficulties using header directly with mysql_query. But solved it by using if(mysql_num_rows($query)==0){header("....");}. Thanks anyway.