0

on index.php i am getting error saying 'undefined index login_user in session.php on line 15' This error appears when i am not logged in. but when i am logged in the error is gone

Login.php

  if (isset( $_POST['login'])) { 
      session_start();
      $log = "SELECT user_id,password FROM user where user_id='".$name."' AND password='".$pswd."' ";
      $result1 = $conn->query($log);
      if ($result1->num_rows == 1) {
          $_SESSION['login_user'] = $name;         // Initializing Session
          header("location: index.php");
      } else {
          if ($result1->num_rows == 0) {
              $msg3 = "user id or password incorrect";
          }
      }
  }

session.php

session_start();    
$user_check = $_SESSION['login_user'];
if ($user_check == "") {
    $flag = 0;
} else {
    $flag = 1;
}
$ses_seq = "SELECT first_name FROM user where user_id='".$user_check."'";
$result2 = mysqli_query($conn,$ses_seq);
$row = mysqli_fetch_assoc($result2);
$login_session = $row["first_name"];

index.php

       include('session.php');
       $w1 = $w2 = "";
       if (isset($_POST['logout'])) { 
           if ($flag) {
               session_destroy();
               header("location: index.php");
           } else {
               header("location: login.php");
           }
       }
Danila Ganchar
  • 10,266
  • 13
  • 49
  • 75
  • @JohnConde you're mistaken. The duplicate refference post is not the solution for OP. – Marcos Pérez Gude Sep 14 '15 at 16:36
  • 1
    @MarcosPérezGude Sorry, but I have to disagree. The linked question clearly answers the OP's question. S(he) is referencing an undefined variable `login_user` from the `$_SESSION` array because it has not been defined. Any of the suggestions in the first answer alone will help prevent the error. It's not a line for line solution to the OP's question and it does require a little effort on their part, but it nonetheless answers the question. – War10ck Sep 14 '15 at 16:48
  • You're right at this point, but the problem of this question is in the sql query, not in the array. So the duplicate flag is wrong. Nothing else – Marcos Pérez Gude Sep 14 '15 at 16:57
  • However it's nothing to do now. This topic is closed – Marcos Pérez Gude Sep 14 '15 at 16:58
  • @MarcosPérezGude The dupe is still correct. That value is never set and the dupe would tell them this. They can then logically deduce their query failed and never set that value. – John Conde Sep 14 '15 at 17:23
  • You're all right, but we can help better a new user like this. We answer very stupid posts and with this I think that OP doesn't solve his problem. Sometimes, people needs an explanation because they are newbie in developing. So sorry for my comments. – Marcos Pérez Gude Sep 14 '15 at 17:26

0 Answers0