title: if query does not exist, redirect to another page
body: <p>This code only redirects to <code>notenrolled.php</code> even if the input value is correct. I want it to continue the process if the value entered is correct. Is there something wrong with my code?</p>
  
  <pre><code>&lt;?php
  //Setup connection to the database 
  $connect = mysql_pconnect("localhost", "root", "") 
  or die(mysql_error()); 
  
  //Connect to the database 
  mysql_select_db("dbgis", $connect) or die(mysql_error());
  
  $query  = "SELECT * from tbl_student WHERE stud_id= '$stud_id' ";
  $result = mysql_query($query);
  $totalrows = mysql_num_rows($result);
  
  
  while($row = mysql_fetch_array($result))
  {
      header("Location: yesno.php");
  }
  
  if($totalrows != 0)
  {
      header("Location: notenrolled.php");
  }
  
  ?&gt;
  </code></pre>
  
  <hr>
  
  <p>I tried the <code>die();</code> and it seems to be working because it just says a redirection looping error with <code>yesno.php</code>. So I think I might have put the code in the wrong <code>.php</code> page. </p>
  
  <p>The flow is like this: I have a <code>guard.php</code> page where I could search a <code>query(stud_id)</code> using my search form in the page. I then want to check whether the query exists and if it doesn't, I want it to redirect to <code>notenrolled.php</code> else if the query is found, I want it to proceed to <code>yesno.php</code>. </p>