Q:

make session for pdo php

base on my question here i was able to make a session but what i dont get is that i dont direct to the welcome page no matter what i do here is the code.
lock.php
<?php
include('config.php');
session_start();
$user_check=$_SESSION['login_user'];
        $stmt = $dbh->prepare("SELECT * FROM member WHERE username = ? ") ;
        $stmt->bindValue(1,$user_check);
        $stmt->execute();
        $selected_row = $stmt->fetch(PDO::FETCH_ASSOC);

$login_session=$selected_row['username'];

if(!isset($login_session))
{
header("Location: login.php");
}
?>

crud.php
<?php 
include_once('config.php');

$error="";

function LoginUser() {
    echo "login";
    global $dbh;
if(!empty($_POST['un'])){
        $username = trim($_POST['un']);
        $password = trim($_POST['pw']);
        $stmt = $dbh->prepare("SELECT * FROM member WHERE username = ? ") ;
        $stmt->bindValue(1,$_POST['un']);
        $stmt->execute();
        $selected_row = $stmt->fetch(PDO::FETCH_ASSOC);
        if($selected_row['username']===$_POST['un']){
            if($selected_row['password']===$_POST['pw']){
                $_SESSION['username'] = $_POST['un'];
                echo $_SESSION['username'];
                header("location: welcome.php");
                die();
            }else{
                echo "incorrect password";
                header("location: login.php");
                die();
            }

        }else{
            echo "user does not exist";
            header("location: login.php");
            die();
        }
}else{
     echo "empty";
     header("location: login.php");
     die();
}
}
function SignUp(){
global $dbh;

if(!empty($_POST['un'])){
        $username = trim($_POST['un']);
        $password = trim($_POST['pw']);
        $stmt = $dbh->prepare("SELECT * FROM member WHERE username = ?") ;
         $stmt->bindValue(1,$_POST['un']);
        $stmt->execute();
        $selected_row = $stmt->fetch(PDO::FETCH_ASSOC);
        //if(!empty($stmt->rowCount())){
        if($selected_row['username']===$_POST['un']){
            //echo "SORRY...YOU ARE ALREADY REGISTERED USER...";
            trigger_error("SORRY...YOU ARE ALREADY REGISTERED USER...");
        }else{
            NewUser();
        }
}else{
    header("location: signup.php");
    die();
}
}

function NewUser(){
    global $dbh;
        $firstname = trim($_POST['fn']); //at a minimus clear whitespace.
        $lastname = trim($_POST['ln']);
        $username = trim($_POST['un']);
        $password =  trim($_POST['pw']);
        $address =  trim($_POST['cp']);
        $stmt = $dbh->prepare("INSERT INTO member (fname,lname,username,password) VALUES (?,?,?,?)");

        $stmt->bindValue(1,$firstname,PDO::PARAM_STR);
        $stmt->bindValue(2,$lastname,PDO::PARAM_STR);
        $stmt->bindValue(3,$username,PDO::PARAM_STR);
        $stmt->bindValue(4,$password,PDO::PARAM_STR);
        if($stmt->execute()){
        echo "YOUR REGISTRATION IS COMPLETED...";
        }
}

if (isset($_POST['signup'])) {
    //action for update here
    SignUp();
}  
if (isset($_POST['login'])) {
    //action for delete
    LoginUser();
} 
if (isset($_POST['register'])) {
    //action for delete
    header("Location: signup.php");
} 
if (isset($_POST['back'])) {
    //action for delete
    header("Location: login.php");
}
?>

login.php
<?php
include_once('crud.php');
include("config.php");
// Inialize session
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Login Page</title>

<style type="text/css">
body
{
font-family:Arial, Helvetica, sans-serif;
font-size:14px;

}
label
{
font-weight:bold;

width:100px;
font-size:14px;

}
.box
{
border:#666666 solid 1px;

}
</style>
</head>
<body bgcolor="#FFFFFF">

<div align="center">
<div style="width:300px; border: solid 1px #333333; " align="left">
<div style="background-color:#333333; color:#FFFFFF; padding:3px;"><b>Login</b></div>

<div style="margin:30px">

<form action="crud.php" method="post">
<form method="POST" action="crud.php">
    <table border="0">
        <form method="POST" action="crud.php">  
            <tr>
                <td>UserName  :</td>
                <td>
                    <input type="text" name="un" class="box"/>
                </td>
            </tr>
            <tr>
                <td>Password  :</td>
                <td>
                    <input type="password" name="pw" class="box" />
                </td>
            </tr>
            <tr>
                <td>
                    <input type="submit" value="Login " name="login"/><br />
                </td>
                <td>
                    <input type="submit" value="Register " name="register"/><br />
                </td>
            </tr>
            <tr><td><div style="font-size:11px; color:#cc0000; margin-top:10px"><?php echo $error; ?></div></td></tr>
        </form>
    </table>
</div>
</div>
</div>

</body>
</html>

welcome.php
<?php include("config.php");?>
<?php include("lock.php");?>
<?php include_once('crud.php'); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Welcome </title>
</head>

<body>
<h1>Welcome <?php echo $login_session; ?></h1> 

<h2><a href="logout.php">Sign Out</a></h2>
</body>
</html>

from the above code there are a few question i have in mind..

Why is it that i am not directing to welcome when infact i log in correctly.
Is it possible that the lock.php is getting nothing?i mean no value for username.
I am using this in local and I cant access debug in chrome so I have no idea where I get error.
fyi this is from a tutorial.

A:

simple answer:
include_once('crud.php');

in the lock.php because it where the data is from.

