title: Php login error - Notice: Undefined index:
body: <p>I looked at previos Undefined error questions to see if I could find help for my question, but I can't seem to fix it for my problem. 
  So when I try to log in a user I get an error that says Undefined index:
  No sure why Im getting this message on my login.php page</p>
  
  <p>I have a database and a table called users with data inserted</p>
  
  <p>this is what I use to connect to the database</p>
  
  <p>conn.php</p>
  
  <pre><code> &lt;?php
     session_start(); 
     $dbhost = "127.0.0.1"; // my database 
     $dbname = "fxdme";
     $dbuser = "root";
     $dbpass = "";
  
     $mysqli = mysqli_connect($dbhost, $dbuser, $dbpass,$dbname) or die("MySQL Error: " .     mysqli_error("Cant Connect"));
  
    ?&gt;
  </code></pre>
  
  <p>the login script</p>
  
  <p>login.php</p>
  
  <pre><code>&lt;?php include 'template/header.php';?&gt;
  
   &lt;form  action="login.php" method="POST"&gt;
    User Name: &lt;input type="text" name="username" /&gt;
     Password: &lt;input type="password" name="password"/&gt;
     &lt;input class="submit" name="submit" type="submit" value="Log In"/&gt;
   &lt;/form&gt;    
  
  
  &lt;?php  
  
  $result=$mysqli-&gt;query('SELECT * FROM users WHERE username = "' .
  $_POST['username'] . '" AND password = "' . $_POST['password'] . '"');
  
  //set session user 
  $row = $result-&gt;fetch_assoc();
  $_SESSION['user_id'] = $row['id'];
  
  if ($_SESSION['user_id']) {    
     echo "You are logged in, $session_username. &lt;a href='logout.php'&gt;Log out&lt;/a&gt;"; } 
  else {
     echo " cant log in";
  } 
  ?&gt;
  </code></pre>
  
  <p>// Index page</p>
  
  <p>My index page
  index.php</p>
  
  <pre><code>//in the template header is where Im calling my conn file 
   &lt;?php include 'template/header.php'; ?&gt;
  
   &lt;?php  
   if (isset($_GET['invalid'])) {         
    echo "&lt;tr&gt;&lt;td colspan='2' align='right'&gt;Invalid login.&lt;/td&gt;&lt;/tr&gt;";    
   }  
   ?&gt;
  </code></pre>
  
  <p>Im trying to get the error fixed so I'm not worried about sql injections at the moment. I    just want to be able to login and and worry about the other stuff later.</p>