title: Undefined index errors on my login form and nothing happens when I try to log in
body: <p>I'm trying to make a login page for my website</p>
  
  <p>I am using xampp at the moment to test before I upload it to my host and made a mysql database with some test data in.</p>
  
  <p>When I go to local localhost/xampp/Login.php I get the errors:
  Notice: Undefined index: username in C:\xampp\htdocs\xampp\Login.php on line 41</p>
  
  <pre><code>Notice: Undefined index: password in C:\xampp\htdocs\xampp\Login.php on line 41
  
  Notice: Undefined index: logout in C:\xampp\htdocs\xampp\Login.php on line 43
  
  Notice: Undefined index: test_account in C:\xampp\htdocs\xampp\Login.php on line 25
  </code></pre>
  
  <p>The first line here is line 41</p>
  
  <pre><code>if($_POST['username'] !='' || $_POST['password'] != '') {
  $login_status = login($_POST['username'], $_POST['password']);
  } else if($_GET['logout']) {
  logout();
  }
  $userid = status();
  </code></pre>
  
  <p>My form sends the data so I don't understand why it gives errors </p>
  
  <pre><code>&lt;form action="Login.php" method="POST"&gt;
  &lt;input type=text name=username&gt;
  &lt;input type=password name=password&gt;
  &lt;input type=submit value="Log In"&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>when I click the login nothing happens, this is the full php file I am using</p>
  
  <pre><code>&lt;?php
  
      $link = mysql_connect("localhost", "admin", "1234");
      mysql_select_db("test_database", $link);
  
  function login($username, $password) {
          $username = addslashes($username);
          $password = md5($password);
      $query = mysql_query("SELECT * FROM user_accounts WHERE username='$username' AND password='$password'");
      if(mysql_num_rows($query) == 1) {
          $info = mysql_fetch_array($query);
          $userid = $info[userid];
          $sessionid = md5($userid . time());
          $time = time();
          @setcookie ('test_account', $sessionid, $time+3600, '/', '');
          mysql_query("DELETE FROM user_sessions WHERE userid='$userid'");
          mysql_query("INSERT INTO user_sessions (sessionid,userid,timestamp) VALUES('$sessionid','$userid','$time')");
          return $userid;
      } else {
          return 0;
      }
  }
  
  function status() {
      $sessionid = $_COOKIE[test_account];
      $oldtime = time() - 3600;
      $query = mysql_query("SELECT * FROM user_sessions WHERE sessionid='$sessionid' AND timestamp&gt;$oldtime");
      if(mysql_num_rows($query) == 1) {
          $info = mysql_fetch_array($query);
          return $info[userid];
      }
      return 0;
  } 
  
  function logout() {
      $sessionid = $_COOKIE[test_account];
      @setcookie ("test_account",'', time()-99999, '/', '');
      mysql_query("DELETE FROM user_sessions WHERE sessionid='$sessionid'");
  }
  
  if($_POST[username] !='' || $_POST[password] != '') {
      $login_status = login($_POST[username], $_POST[password]); 
  } else if($_GET[logout]) {
      logout();
  }
  $userid = status();
  
  
  if($userid &gt; 0) { echo "Welcome to our site, user #$userid (&lt;a href='?logout'&gt;Click here to logout&lt;/a&gt;)"; } else {
  
  if($login_status != '' $login_status == 0) { echo "Invalid username/password combo.&lt;br&gt;"; }
  ?&gt;
  
  &lt;form action="sample.php" method="POST"&gt;
  &lt;input type=text name=username&gt;
  &lt;input type=password name=password&gt;
  &lt;input type=submit value="Log In"&gt;
  &lt;/form&gt;
  
  &lt;?php } ?&gt;
  </code></pre>