-1

When I print the print_r($SESSION) function it shows up empty. Here is the code below (ps. dont worry about SQL injection at the moment).

Everything else works PERFECTLY, errors show up perfectly. Its just the session values come up empty!

<?php
session_start();
include 'dbconnect.php';
$emailerror = $passworderror = "";

if(isset($_POST['submit']))
{


    $email= $_POST["email"];
    $password= $_POST["password"];

    if (empty($email)) {
        $emailerror = "*Email must be entered";
    }

    elseif (!filter_var($email, FILTER_VALIDATE_EMAIL))
    {   
        $emailerror= "*Invalid email address Entered";    
    }

    // To check if email has already been used or if another account with the same email exists
    else{         
        $emailquery = ("SELECT * FROM `Potential_Employee` WHERE `Email` = '$email'");
        $emailcheckresult = mysqli_query($connection, $emailquery);


        if(mysqli_num_rows($emailcheckresult) == 1){            
            $row=mysqli_fetch_assoc($emailcheckresult);

            if (!password_verify($password, $row['Password'])){
                $passworderror = "*Password is incorrect!";
            }
            else{
                $_SESSION['Email'] = $email;
                $_SESSION['logged_in'] = true;
                echo "<script>document.location='EmployeeDashboard.php';</script>";

            }

        }
        else{
            $emailerror = "*Email does not exist";
        }

    }

    if (empty($password)) {
        $passworderror = "*Password must be entered";
    }

    elseif (strlen($password) < 4 )
    {
        $passworderror= "*Password Has to be greater than 8 Characters";
    }
AdrianC
  • 77
  • 6
  • A little tip, I wont mention the SQLi.. If you store your errors eg. `$emailerror, $passworderror` in an array like `$errors['email'], $errors['password']` you can simply check if its empty, else there has been an error of sorts. It will make it much cleaner with nicer grouping, easier to pass to views etc, and once you move onto a form with 20+ input you wont need to remember all them global vars, just debug that one var. Happy coding.. – Lawrence Cherone Dec 02 '17 at 02:25
  • Good point @LawrenceCherone Happy Coding – Amit Gupta Dec 02 '17 at 02:29
  • @LawrenceCherone ah ok thank you. – AdrianC Dec 02 '17 at 12:45

2 Answers2

-1

You need to debug SESSION like below:

print_r($_SESSION);

Or

echo '<pre>' . print_r($_SESSION, TRUE) . '</pre>';
// Make second argument TRUE so it will return instead of echo

Or

echo '<pre>';
var_dump($_SESSION);
echo '</pre>';
Amit Gupta
  • 2,771
  • 2
  • 17
  • 31
-1

Looks like it's just a typo.

use:

$_SESSION

not

$SESSION

so this should work:

print_r($_SESSION)

https://www.w3schools.com/php/php_sessions.asp