未定义的索引:sessionName

Hello I have created a login page which is

 <form method="POST" action="log.php">

<table border="1" cellpadding="4" cellspacing="0"
    style="font-family: arial; font-size: 15px; border: 0px; text-align: left; margin-top: 5px; background-color: transparent;"
    width="100%">
    <thead>
        <tr>
            <td style="border: 0px; width: 20%; background-color: transparent;">
                Username:</td>
            <td style="border: 0px; width: 30%; background-color: transparent;">
                <input type="text" name="email" id="email" class="form-control"
                autocomplete="off" required="">
            </td>
        </tr>
    </thead>
</table>

<table border="1" cellpadding="4" cellspacing="0"
    style="font-family: arial; font-size: 15px; border: 0px; text-align: left; margin-top: 5px; background-color: transparent;"
    width="100%">
    <thead>
        <tr>
            <td style="border: 0px; width: 20%; background-color: transparent;">
                Password:</td>
            <td style="border: 0px; width: 30%; background-color: transparent;">
                <input type="password" name="pass" id="pass" class="form-control"
                autocomplete="off" required>
            </td>
        </tr>
    </thead>
</table>
</div>


<div class="spacer-20"></div>

</div>
<!-- Social Signup -->
<div class="social-signup">
    <span class="or-break"></span>
    <center>
    <button type="submit" name="login" class="btn btn-primary">
        <span class="glyphicon glyphicon-log-in"></span> Login
    </button>
    No account? <a href="joinus.php"> Sign up</a>

</form>

and the login Processor is as follows

<?php
// Login Controller
// require('config/config.php');
include './config/config.php';
$userName = $passWord = $name = "";

if (isset ( $_POST ['login'] )) {
    $userName = mysqli_real_escape_string ( $con, $_POST ['email'] );
    $password = mysqli_real_escape_string ( $con, $_POST ['pass'] );
    $pass = md5 ( $password );
    // Block handles Doctor Login using the email
    $get_doc = "SELECT * FROM doctor_registration WHERE email='$userName' AND password='$pass'";
    $run_doc = mysqli_query ( $con, $get_doc );
    $rows = mysqli_fetch_array ( $run_doc );
    $docId = $rows ['doc_id'];
    $docEmail = $rows ['email'];
    $name = $rows ['first_name'] . " " . $rows ['last_name'];
    
    if ($userName == $docEmail) {
        $_SESSION ['sessionName'] = $name;
        $_SESSION ['sessionId'] = $docId;
        echo "<script>window.open('doctor_dashboard.php','_self')</script>";
    } else {
        // Block handles user Login using the username
        $get_user = "SELECT * FROM users WHERE username='$userName' AND password='$pass'";
        $run_user = mysqli_query ( $con, $get_user );
        $rows = mysqli_fetch_array ( $run_user );
        $userId = $rows ['user_id'];
        $uname = $rows ['username'];
        if ($userName == $uname) {
            $_SESSION ['sessionName'] = $uname;
            $_SESSION ['sessionId'] = $userId;
            echo "<script>window.open('user_dashboard.php','_self')</script>";
        } else {
            echo "<script>alert('Passowrd or username is not correct!')</script>";
        }
    }
}
?>

and for the dashboard the processor checks the email or username and redirects to one of the dashboard.

i have two dashboards which have the code bellow for starting and storing a session

<?php
    session_start ();
    include './config/config.php';
    include './updateFunction.php';
    include './InsertFunction.php';
    
    if (isset ( $_SESSION ['sessionName'] ) && ($_SESSION ['sessionId'])) {
        header ( "location:index.php" );
    }
?>

and each time i try to login in both dashboards i get the error:

Undefined index: sessionName

</div>

You should use session_start() before using $_SESSION['sessionName'] = $name

in the login processor.

So preferably you should use session_start() at the beginning of the page

Put session_start(); in your config.php after <?php

then call config.php on every page on after <?php

you are getting session error because you haven't use session_start(); in your file