I am trying to create a forum from scratch, and i got a bit tangled. In the following code, i'm trying to put a condition that if the user is not logged in, he cannot add a category. However, the code works perfectly if the user is logged, but i get an "undefined index: userid if he is not. I tried to add if(isset($_SESSION['userid'])) but that's just gonna hide the notice "you have to be signed in". any awesome ideas?
<?php
include("_/inc/dbcon.php");
    $link = mysql_connect($host, $login, $pw);
    mysql_select_db($database);
    if($link){
    }
include("_/inc/session_handler.php");
$create_cat ="";
if($_SESSION['userid'] == false /*| $_SESSION['rank'] !='Emperor' || $_SESSION['rank'] !='Destroyer' ||  $_SESSION['rank']!= 'Tekken Lord' )*/)
{
    //the user is not an admin
    echo 'Sorry, you do not have sufficient rights to access this page.';
}
else
{
    //the user has admin rights
    if($_SERVER['REQUEST_METHOD'] != 'POST')
    {   echo "YOU HAVE THE RIGHTS!";
        //the form hasn't been posted yet, display it
        $create_cat .= '<form method="post" action="">
            <input type="text" name="cat_name" placeholder="Category Name"/><br />
            <input type="text" name="cat_description" placeholder="Category Description" /><br />
            <input type="submit" value="Add category" />
         </form>';
    }
    else
    {
        //the form has been posted, so save it
        $sql = "INSERT INTO sp_categories(cat_name, cat_description)
           VALUES('" . mysql_real_escape_string($_POST['cat_name']) . "',
                 '" . mysql_real_escape_string($_POST['cat_description']) . "')";
        $result = mysql_query($sql);
        if(!$result)
        {
            //something went wrong, display the error
            echo 'Error' . mysql_error();
        }
        else
        {
            $create_cat .=  'New category succesfully added.';
        }
    }
}
?>
 
     
     
    