-1

I am having problems logging in to php. is says Notice: Undefined index: log in.. i tried fixing it on my own but it just got worst T_T please help me guys

here is the line that is having an error

>$user = $_SESSION['log']['username'];

here is the whole code >

<?php
include("session/DBConnection.php");

$user = $_SESSION['log']['username'];
            $query = mysql_query("SELECT * FROM members WHERE username = '$user'") or die (mysql_error()); 
            $display = mysql_fetch_array($query);   ?>
Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
pande lemon
  • 21
  • 1
  • 1
  • 4
  • 1
    So where's the code that sets the session variable `log`? – enhzflep Jun 24 '13 at 04:02
  • If ($numberOfRows == 0) { echo " Invalid username and password! "; } else if ($numberOfRows > 0) { (isset($_SESSION['is'])); $_SESSION['log']['login'] = TRUE; $_SESSION['log']['username'] = $_POST['username']; $session = "1"; $query = mysql_query("SELECT * FROM members WHERE username = '$username'") or die (mysql_error()); $display = mysql_fetch_array($query); – pande lemon Jun 24 '13 at 05:47

2 Answers2

1

change this to:

if(isset($_SESSION['log']['username'])) { // add this IF statement to check the variable is set or not
   $user = $_SESSION['log']['username'];
   $query = mysql_query("SELECT * FROM members WHERE username = '$user'") or die (mysql_error()); 
   $display = mysql_fetch_array($query);
}
skparwal
  • 1,086
  • 6
  • 15
1

Probably because $_SESSION['log']['username']; is empty.

Add line for testing it, example:

if(!empty($_SESSION['log']['username']))
    {
     //your sql query
     ....

    }
Dorian_gd
  • 181
  • 1
  • 13
  • What do you mean when you say `empty`? Does `""` (an empty string) fits your "empty" term definition? – zerkms Jun 24 '13 at 23:20
  • yes, so $user values is empty too. Maybe you can show use in your code when you declare your $_SESSION variable (not in comments) – Dorian_gd Jun 25 '13 at 00:13
  • 1. Om not an OP 2. If there is an empty string there - there will be no undefined index notice – zerkms Jun 25 '13 at 00:20