Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It appears as though you are nesting that redirection inside the while loop. Since there are no rows, the while condition <code>mysql_fetch_array()</code> will immediately return <code>FALSE</code> and skip the whole block, including the redirection you intended it to follow. </p> <p>Move the test for <code>mysql_num_rows()</code> outside the <code>while</code> loop.</p> <pre><code>// Test for rows and redirect BEFORE entering the while loop. if (mysql_num_rows($result1) === 0) { header("Location: new.php"); // Always explicitly call exit() after a redirection header! exit(); } // Otherwise, there are rows so loop them. while($line=mysql_fetch_array($result1,MYSQL_ASSOC)) { $email=$line['email']; $group=$line['group']; if($group == 1){ header("Location: facilitator.php"); } } </code></pre> <p>You actually may not need a <code>while</code> loop at all, depending on how many rows you are expecting to fetch. If you only expect one group per email, then forego the loop and just call <code>$line = mysql_fetch_array()</code> once. However, if you are expecting multiple rows but want to redirect on the first one encountered where <code>$group == 1</code>, then your logic works. In that case however, since you are only doing the redirection and no other action, you might as well just put that condition in your query:</p> <pre><code>// Test the group in your query in the first place. $query = "select * from usergroup where email='$fromaddr' AND group = 1"; $result1 = mysql_query($query) or die($query."&lt;br/&gt;&lt;br/&gt;".mysql_error()); if (mysql_num_rows($result1) === 0) { // you didn't match a row, redirect to new.php } else { // you had a match, redirect to facilitator.php } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload