title: Remember Me "Undefined Index" Error
body: <p>I have created a page that allow for logging in. There are a couple of other pages used for connecting to database and redirting to another page after a successful login, etc. Anyway, there is a variable I have used called "$rememberme" which checks if the remember me checkbox is checked or not. Problem is, when I enter a wrong password, it says, "Notice: Undefined index: rememberme in /home/stud/1/1520621/public_html/Car_Club_Task2/index.php on line 30". I checked line 30 and that is where the $rememberme variable is declared.</p>
  
  <p>Any suggestions? Probably something really simply I'm missing!</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  
  
  &lt;html&gt;
      &lt;head&gt;
        &lt;title&gt;Midlands Car Club&lt;/title&gt;
        &lt;link rel="stylesheet" type="text/css" href="styles.css" media="screen"&gt;
      &lt;/head&gt;
  
      &lt;div id="header"&gt;
        &lt;h1&gt;Midlands Car Club Log-In&lt;/h1&gt;
      &lt;/div&gt;    
  
      &lt;?php
      include 'connect.php';
  
      //if logged in equals true (running loggedin function from connect.php page)
      if(loggedin())
      { 
        //redirects to welcome.php if logged in
        header("Location: welcome.php");
        //for browsers that don't allow redirect headers
        exit();
      }
  
      // Has submit button been pressed?
      if (isset($_POST['login']))
      {
        //get data
        $username = $_POST['username'];
        $password = $_POST['password'];
        $rememberme = $_POST['rememberme'];
  
        //if username AND password have been entered
        if ($username&amp;&amp;$password)
        {
          //select all from Login table
          $login = mysql_query("SELECT * FROM Login WHERE Username='$username'");
          // can refer to particular coloumns. Creating array of all data found in above query
          while($row = mysql_fetch_assoc($login))
          {
            //row equal to array - where it finds username in db, it finds password in that row because of column name
            $db_password = $row['Password'];
            if ($password==$db_password)
            {
              //create variable with value true (boolean)
              $loginOK = TRUE;
            }
            else
            {
              //create variable with value false (boolean)
              $loginOK = FALSE;
            }
  
            if ($loginOK==TRUE)
            {
              //if remember me selected
              if ($rememberme=="on")
                // set cookie with current time plus 48 hours (write time in seconds)
                setcookie("username", $username, time()+7200);
              // if remember me not selected
              else if ($rememberme=="")
                //value of session is equal to value of username
                $_SESSION['username']=$username;
  
              //redirect
              header("Location: welcome.php");
              //if header redirect is disabled in browser
              exit();     
            }
            else
            {
              die("Incorrect Username or Password");
            }
          }        
        }
        else
        {
          // kill script
          die("Please enter username and password");
        }
  
      }
  
      ?&gt;    
      &lt;body&gt;
        &lt;div class="add"&gt;          
          &lt;form method="POST" action="index.php"&gt;
          Username: &lt;input type="text" name="username"&gt;&lt;br&gt;
          Password: &lt;input type="password" name="password"&gt;&lt;br&gt;
          &lt;input type="checkbox" name="rememberme"&gt;Remember Me&lt;br&gt;
          &lt;input type="submit" name="login" value="Log In"&gt;
          &lt;/form&gt;
        &lt;/div&gt;
      &lt;/body&gt;
    &lt;/html&gt;
  </code></pre>