I am trying to failing to figure out how to add my user_id from my database to a session like my username is. I would like it so when I log in I can called the session to call the user id posts based on the username used to log in.
How do I do this?
my login php:
<?php
session_start();
$connect = mysql_connect( "localhost", "user", "pass") or die('Database could not connect');
$select = mysql_select_db( "database", $connect) or die('Database could not select');
if (isset($_POST['submit'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    chckusername($username, $password);
}
function chckusername($username, $password){
    $check = "SELECT * FROM users WHERE username='$username'";
    $check_q = mysql_query($check) or die("<div class='loginmsg'>Error on checking Username<div>");
    if (mysql_num_rows($check_q) == 1) {
        chcklogin($username, $password);
    }
    else{
        echo "<div id='loginmsg'>Wrong Username</div>";
    }
}
function chcklogin($username, $password){
    $login = "SELECT * FROM users WHERE username='$username'  and password='$password' ";
    $login_q = mysql_query($login) or die('Error on checking Username and Password');
print_r($lohin_q);
    if (mysql_num_rows($login_q) == 1){
        header('Location: http://ct6014-williams.studentsites.glos.ac.uk/pages-multi-page/home.php');        
        $_SESSION['username'] = $username;
        $_SESSION['user_id'] = $userid; //this is where I want to store the user id
    }
    else {
        echo "<div id='loginmsg'>Wrong Password </div>"; 
    }
}
?>
on home.php:
<?php echo "Your username is " . $_SESSION["username"] . "."; ?>    
     <?php echo "Your id is " . $_SESSION["user_id"] . "."; ?>
database names:
user_id, username, user_first_name, user_last_name, user_email, password, user_reg_date
EDIT:
Ahh, I forgot to say, I have used include( 'login.php' ); which created the session when I logged in as a user. The first username session echos but I cannot seem to figure out hoe to set up the user_id session
 
     
    