1

so I been getting this issue on my login page where its unable to find a variable I set but I have made sure its on the database. I have compared it with the databse and it all seems to match so I am not sure why im getting this error. Please find details below. Thank you for your help :)

Error : Notice: Undefined variable: ID in /home/scylla97/public_html/login.php on line 89

Code :

            $SQLCheckLogin = $odb -> prepare("SELECT COUNT(*) FROM `users` WHERE `username` = :username AND `password` = :password");
        $SQLCheckLogin -> execute(array(':username' => $username, ':password' => SHA1($password)));
        $countLogin = $SQLCheckLogin -> fetchColumn(0);
        if ($countLogin == 1)
        {
            $SQLGetInfo = $odb -> prepare("SELECT `access`, `username`, `ID`, `rank` FROM `users` WHERE `username` = :username AND `password` = :password");
            $SQLGetInfo -> execute(array(':username' => $username, ':password' => SHA1($password)));
            $userInfo = $SQLGetInfo -> fetch(PDO::FETCH_ASSOC);
            if ($userInfo['access'] == 0)
            {
                $_SESSION['username'] = $userInfo['username'];
                $_SESSION['ID'] = $userInfo['ID'];
                {
                    $ip = getRealIpAddr();
                    if (filter_var($ip, FILTER_VALIDATE_IP))
                    {
                        $SQL = $odb -> prepare('INSERT INTO `logs` VALUES(:id ,:username, :loggedip, UNIX_TIMESTAMP())');
                        $SQL -> execute(array(':loggedip' => $ip, ':username' => $username, ':id' => $id));
                        echo '<div class="nNote nSuccess hideit"><p><font color=\'white\'><strong>SUCCESS: </strong>Login Successful. Redirecting....</font></p></div><meta http-equiv="refresh" content="3;url=index.php">';
                        die();

Line 89 is :

$SQL -> execute(array(':loggedip' => $ip, ':username' => $username, ':id' => $id));

Database of Logs : Its the logs table on phpmyadmin

I apologies in advanced if this is a stupid question and really easy to fix but I have spent the last few hours looking at it and playing around with it but still no fix.

Masivuye Cokile
  • 4,754
  • 3
  • 19
  • 34
user3657631
  • 45
  • 1
  • 5

1 Answers1

1

you miss your $id value and hope your $username already you get so first assign value using $id like

$id = $userInfo['ID'];

so add this line

$_SESSION['username'] = $userInfo['username'];
$_SESSION['ID'] = $userInfo['ID'];
$id = $userInfo['ID'];

so your query

 $SQL -> execute(array(':loggedip' => $ip, ':username' => $username, ':id' => $id));

or update your query

$SQL -> execute(array(':loggedip' => $ip, ':username' => $username, ':id' => $_SESSION['ID']));

hope it will help you

Shafiqul Islam
  • 5,570
  • 2
  • 34
  • 43