title: Simple PHP Login - redirecting to a new webpage after successful login
body: <p>I'm using the script below for logging in. I'm trying to redirect the users who were succesfully logged in to another webpage (visible only for logged in users), but it redirects everyone - regardless if the username and password are correct. What's should be changed in the code?
  <br>
  page with login form - <code>index.php</code> <br>
  the page that I want to redirect to - <code>content.php</code> <br></p>
  
  <p><br>
  <strong>Table in my database</strong></p>
  
  <pre><code>CREATE TABLE `person` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `name` varchar(255) NOT NULL,
    `emailadress` varchar(255) NOT NULL,
    `pass` varchar(255) NOT NULL,
    PRIMARY KEY (`id`),
  )
  </code></pre>
  
  <p><strong>PHP</strong></p>
  
  <pre><code>&lt;?php 
  if (isset($_POST['username']) and isset($_POST['password'])){
  $name = $_POST['username'];
  $pass = $_POST['password'];
  
  $query = "SELECT * FROM `person` WHERE name='$username' and pass='$password'";
  $result = mysql_query($query) or die(mysql_error());
  $count = mysql_num_rows($result);
  if ($count == 1){
  $_SESSION['username'] = $username;
  }else{
  echo "Login failed.";
  }
  }
  if (isset($_SESSION['username'])){
  $username = $_SESSION['username'];
  echo "Hello" . $username . "
  ";
  echo "&lt;a href='logout.php'&gt;Logout&lt;/a&gt;";}
  ?&gt;
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;form method="post" action="content.php" name="login"&gt;
  
  &lt;?php
      if(isset($msg) &amp; !empty($msg)){
          echo $msg;
      }
   ?&gt;        
          &lt;label for="username"&gt;Username:&lt;/label&gt;&lt;br&gt;
          &lt;input type="text" name="username"&gt;&lt;br&gt;
          &lt;label for="password"&gt;Password:&lt;/label&gt;&lt;br&gt;
          &lt;input type="password" name="password"&gt;&lt;br&gt;
          &lt;button type="submit" name="login"&gt;Log in&lt;/button&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p><br><br></p>