title: how to use database data to determine what action to take
body: <p>I am looking to have a page with a redirect based on what is in the database.
  I have a table called &quot;nametable&quot; and 2 columns &quot;id&quot; and &quot;switch&quot;
  The id never changes, only the switch entry does. Sometimes it will have &quot;on&quot; as the entry, and sometimes it will have &quot;off&quot; as the entry (depending on what I enter in there at the time)</p>
  <p>So I want a page where the website visitor will go to, and if the database says &quot;on&quot; then they will be redirected to, lets say &quot;pageon.php&quot; and if it says off, the visitor will be redirected to &quot;pageoff.php&quot;</p>
  <p>I managed to do a simple echo to show on or off in text on the page. But I don't have the foggiest on how to have them redirected based on that.</p>
  <p>Any thoughts on what I should search for to make this happen? And advice is appreciated.</p>
  <p>PS. I tend to get a -1 because the site thinks I'm not specific on what I am wanting to do. If I am unclear, please tell me so I can revise before closing or -1</p>
  <p>Thank you</p>
  <p>EDIT: Based on the advice I was given in the comments, I have made this so far. I'm only getting a blank page though. Any thoughts?</p>
  <pre><code>
      &lt;?php
      $servername = &quot; &quot;;
      $username = &quot; &quot;;
      $password = &quot; &quot;;
      $dbname = &quot; &quot;;
      
      // Create connection
      $conn = new mysqli($servername, $username, $password, $dbname);
      // Check connection
      if ($conn-&gt;connect_error) {
        die(&quot;Connection failed: &quot; . $conn-&gt;connect_error);
      }
      
      $sql = &quot;SELECT id, switch FROM nametable&quot;;
      $result = $conn-&gt;query($sql);
      
      
      if ($row['switch'] == &quot;on&quot;) header(&quot;Location: off.php&quot;); else header(&quot;Location: on.php&quot;);
      
      
      
      $conn-&gt;close();
      ?&gt;
  
   
  </code></pre>