I have a problem with login issue that when i loggin as student from index.php it should bring me to student_home php.. but it doesnt show anything and just bring me to index.php back.. i mixed up about header and session part..

my index.php

<?php
    include('header.php');
    //Start session
    session_start();
    //Unset the variables stored in session
    unset($_SESSION['id']);
    ?>
    <body>

        <?php include('navhead.php'); ?>

        <div class="container">
            <div class="row-fluid">
                <div class="span3">

                    <div class="hero-unit-3">
                        <div class="alert-index alert-success">
                            <i class="icon-calendar icon-large"></i>
                            <?php
                            $Today = date('y:m:d');
                            $new = date('l, F d, Y', strtotime($Today));
                            echo $new;
                            ?>
                        </div>
                    </div>

                    <div class="hero-unit-1">
                        <ul class="nav  nav-pills nav-stacked">


                            <li class="nav-header">Links</li>
                            <li class="active"><a href="#"><i class="icon-home icon-large"></i> Home
                                    <div class="pull-right">
                                        <i class="icon-double-angle-right icon-large"></i>
                                    </div> 
                                </a></li>

                            <li><a href="sitemap.php"><i class="icon-sitemap icon-large"></i> Site Map
                                    <div class="pull-right">
                                        <i class="icon-double-angle-right icon-large"></i>
                                    </div> 
                                </a></li>
                            <li><a href="contact.php"><i class="icon-envelope-alt icon-large"></i> Contact Us
                                    <div class="pull-right">
                                        <i class="icon-double-angle-right icon-large"></i>
                                    </div> 
                                </a>                
                            </li>
                            <li class="nav-header">About US</li>
                            <li><a  href="#mission" role="button" data-toggle="modal"><i class="icon-book icon-large"></i> Mission
                                    <div class="pull-right">
                                        <i class="icon-double-angle-right icon-large"></i>
                                    </div> 
                                </a></li>
                            <li><a href="#vision" role="button" data-toggle="modal"><i class="icon-book icon-large"></i> Vision
                                    <div class="pull-right">
                                        <i class="icon-double-angle-right icon-large"></i>
                                    </div> 
                                </a></li>
                            <li><a href="history.php"><i class="icon-list-alt icon-large"></i> History
                                    <div class="pull-right">
                                        <i class="icon-double-angle-right icon-large"></i>
                                    </div> 
                                </a></li>

                        </ul>
                    </div>
                    <br>


                </div>
                <div class="span9">
                    <section class="main">
                        <div class="custom-calendar-wrap">
                            <div id="custom-inner" class="custom-inner">
                                <div class="custom-header clearfix">
                                    <nav>
                                        <span id="custom-prev" class="custom-prev"></span>
                                        <span id="custom-next" class="custom-next"></span>
                                    </nav>
                                    <h2 id="custom-month" class="custom-month"></h2>
                                    <h3 id="custom-year" class="custom-year"></h3>
                                </div>
                                <div id="calendar" class="fc-calendar-container"></div>
                            </div>
                        </div>
                    </section>


                    <div class="alert alert-info">
                        <button type="button" class="close" data-dismiss="alert">×</button>
                        <strong>Head Up!</strong> Welcome to Morpheus.
                    </div>
                    <div class="slider-wrapper theme-default">
                    <?php include('slider.php'); ?>
                    </div>
                    <!-- end slider -->
                </div>

            </div>

        </div>
        <!---------------->
        <div class="container">

            <div class="row-fluid">
                <div class="span12">

                    <div class="row-fluid">
                        <div class="span9">
                            <div class="alert alert-success"><i class="icon-file icon-large"></i> <strong>Mission</strong></div>
                            <div class="hero-unit-2">
                                Announcements

                            </div>

                        </div>
                        <div class="span3">
                            <div class="alert alert-info">
                                <i class="icon-building icon-large"></i> Faculty

                            </div>
                            <div class="hero-unit-3">
                                <p><a href=""><i class="icon-sign-blank"></i> Faculty</a></p>
                                <p><a href=""><i class="icon-sign-blank"></i> Faculty</a></p>
                                <p><a href=""><i class="icon-sign-blank"></i> Faculty</a></p>
                                <p><a href=""><i class="icon-sign-blank"></i> Faculty</a></p>
                            </div>
                        </div>
                    </div>
                </div>
            </div>



            <br>
            <div class="alert alert-success"><i class="icon-file icon-large"></i> <strong>Project</strong></div>
            <div class="hero-unit-2">
             Project
            </div>

            <?php include('footer.php'); ?>
        </div>

    </body>
    </html>

navhead.php

<div class="row-fluid">
    <div class="span12">

        <div class="navbar navbar-fixed-top navbar-inverse">
            <div class="navbar-inner">
                <div class="container">

                    <a class="btn btn-navbar" data-toggle="collapse" data-targer=".nav-collapse">
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </a>


                    <div class="nav-collapse collapse">

                        <i class="icon-facebook-sign icon-large" id="color_white"></i>
                        <i class="icon-twitter icon-large" id="color_white"></i>
                        <i class="icon-google-plus icon-large" id="color_white"></i>
                        <i class="icon-github-alt icon-large" id="color_white"></i>
                        <i class="icon-linkedin-sign icon-large" id="color_white"></i>
                        <div class="pull-right">
                            <form class="navbar-search pull-left">
                                <i class="icon-search icon-large" id="color_white"></i>
                                <input type="text" class="search-query" placeholder="Search">

                            </form>
                        </div>
                    </div>        



                </div>
            </div>

        </div>

    </div>


</div>
        <div class="hero-unit-header">
            <div class="container">

                <div class="row-fluid">
                    <div class="span12">
                        <div class="row-fluid">
                            <div class="span6">
                                <img src="admin/images/head.png">
                            </div>
                            <div class="span6">
                                <div class="pull-right">
                                    <!--- login button -->                           
                                    <div class="btn-group">
                                        <button class="btn btn-success"><i class="icon-signin icon-large"></i> Login</button>
                                        <button class="btn dropdown-toggle" data-toggle="dropdown">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li><a href="#student" role="button"  data-toggle="modal"><i class="icon-user icon-large"></i> Student</a></li>
                                            <li><a href="#teacher" role="button"  data-toggle="modal"><i class="icon-user-md icon-large"></i> Teacher</a></li>

                                        </ul>
                                    </div>

                                    <!-- end login -->
                                    <?php include('student_modal.php'); ?>
                                    <?php include('teacher_modal.php'); ?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

            </div>


        </div>

student_modal.php

<div id="student" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-header">

    </div>
    <div class="modal-body">

        <div class="alert alert-info">
            <button type="button" class="close" data-dismiss="alert">×</button>
            <strong>Login Student!</strong> Please Enter the Details Below.
        </div>
        <form class="form-horizontal" method="post">
            <div class="control-group">
                <label class="control-label" for="inputEmail">Username</label>
                <div class="controls">
                    <input type="text" name="username" id="inputEmail" placeholder="Username">
                </div>
            </div>
            <div class="control-group">
                <label class="control-label" for="inputPassword">Password</label>
                <div class="controls">
                    <input type="password" name="password" id="inputPassword" placeholder="Password">
                </div>
            </div>


            <div class="control-group">
                <div class="controls">
                    <button type="submit" name="login" class="btn btn-info"><i class="icon-signin icon-large"></i> Sign in</button>
                </div>


            </div>

            <?php
            if (isset($_POST['login'])) {

                function clean($str) {
                    $str = @trim($str);
                    if (get_magic_quotes_gpc()) {
                        $str = stripslashes($str);
                    }
                    return mysql_real_escape_string($str);
                }

                $username = clean($_POST['username']);
                $password = clean($_POST['password']);

                $query = mysql_query("select * from student where username='$username' and password='$password'") or die(mysql_error());
                $count = mysql_num_rows($query);
                $row = mysql_fetch_array($query);


                if ($count > 0) {
                    session_start();
                    session_regenerate_id();
                    $_SESSION['id'] = $row['student_id'];
                    header('location:student_home.php');
                    session_write_close();
                    exit();
                } else {
                    header('error_login.php');

                    ?>

                    <?php
                }
            }
            ?>

        </form>


        <!-- teacher -->




    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true"><i class="icon-remove-sign icon-large"></i> Close</button>

    </div>
</div>

login_student.php

<?php
include('header.php');
//Start session
session_start();
//Unset the variables stored in session
unset($_SESSION['id']);
?>
<body>

    <?php include('navhead.php'); ?>

    <div class="container">
        <div class="row-fluid">
            <div class="span10">
                <ul class="breadcrumb">
                    <li class="active">Login<span class="divider">/</span></li>
                    <li><a href="login_student.php"><i class="icon-group icon-large"></i> Teacher</a><span class="divider">/</span></li>
                    <li  class="active"><i class="icon-group icon-large"></i> Student</li>

                    <div class="pull-right">       
                        <li>   
                            <i class="icon-calendar icon-large"></i>
                            <?php
                            $Today = date('y:m:d');
                            $new = date('l, F d, Y', strtotime($Today));
                            echo $new;
                            ?>
                        </li>
                    </div>  
                </ul>

                <div class="alert alert-info">
                    <button type="button" class="close" data-dismiss="alert">×</button>
                    <strong>Login Student!</strong> Please Enter the Details Below.
                </div>

                <form class="form-horizontal" method="post">
                    <div class="control-group">
                        <label class="control-label" for="inputEmail">Username</label>
                        <div class="controls">
                            <input type="text" name="username" id="inputEmail" placeholder="Username">
                        </div>
                    </div>
                    <div class="control-group">
                        <label class="control-label" for="inputPassword">Password</label>
                        <div class="controls">
                            <input type="password" name="password" id="inputPassword" placeholder="Password">
                        </div>
                    </div>


                    <div class="control-group">
                        <div class="controls">
                            <button type="submit" name="login" class="btn btn-info"><i class="icon-signin"></i> Sign in</button>
                        </div>


                    </div>

                    <?php

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

                        function clean($str) {
                            $str = @trim($str);
                            if (get_magic_quotes_gpc()) {
                                $str = stripslashes($str);
                            }
                            return mysql_real_escape_string($str);
                        }

                        $username = clean($_POST['username']);
                        $password = clean($_POST['password']);

                        $query = mysql_query("select * from user where username='$username' and password='$password'") or die(mysql_error());
                        $count = mysql_num_rows($query);
                        $row = mysql_fetch_array($query);


                        if ($count > 0) {
                            session_start();
                            session_regenerate_id();
                            $_SESSION['id'] = $row['user_id'];
                            header('location:student_home.php');
                            session_write_close();
                            exit();
                        } else {
                            session_write_close();
                            ?>
                            <div class="pull-right">   
                                <button type="button" class="close" data-dismiss="alert">×</button>
                                <div class="alert alert-danger"><i class="icon-remove-sign"></i> Access Denied</div>
                            </div>
                            <?php
                            exit();
                        }
                    }
                    ?>

                </form>




            </div>
            <div class="span2">

                <div class="hero-unit-1">
                    <ul class="nav  nav-pills nav-stacked">
                        <li class="nav-header">Links</li>
                        <li><a href="index.php"><i class="icon-home icon-large"></i> Home</a></li>
                        <li><a href="#"><i class="icon-file-alt icon-large"></i> New And Events</a></li>
                        <li><a href="#"><i class="icon-sitemap icon-large"></i> Site Map</a></li>
                        <li><a href="#"><i class="icon-envelope-alt icon-large"></i> Contact Us</a></li>
                        <li class="nav-header">About US</li>
                        <li><a href="#"><i class="icon-book icon-large"></i> Mission</a></li>
                        <li><a href="#"><i class="icon-book icon-large"></i> Vision</a></li>
                        <li><a href="#"><i class="icon-list-alt icon-large"></i> History</a></li>

                    </ul>
                </div>

            </div>
        </div>
        <?php include('footer.php'); ?>
    </div>






</body>
</html>

heare is the header.php

<!DOCTYPE html>
<html lang="en">
    <head>

        <title>Morpheus</title>
        <link href="admin/img/chmsc.png" rel="icon" type="image">
        <link href="admin/css/bootstrap.css" rel="stylesheet" type="text/css" media="screen">
        <link href="admin/css/bootstrap-responsive.css" rel="stylesheet" type="text/css" media="screen">
        <link href="admin/css/font-awesome.min.css" rel="stylesheet" type="text/css" media="screen">
        <link rel="stylesheet" type="text/css" href="admin/css/DT_bootstrap.css">
        <?php include('admin/connect.php'); ?>
    </head>
    <script src="admin/js/jquery.js" type="text/javascript"></script>
    <script src="admin/js/bootstrap.js" type="text/javascript"></script>

    <script type="text/javascript" charset="utf-8" language="javascript" src="admin/js/jquery.dataTables.js"></script>
    <script type="text/javascript" charset="utf-8" language="javascript" src="admin/js/DT_bootstrap.js"></script>
    <script type='text/javascript' language='javascript' src='js/ndhui.js'></script>


<!--slider -->
    <link rel="stylesheet" href="admin/themes/default/default.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="admin/themes/light/light.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="admin/themes/dark/dark.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="admin/themes/bar/bar.css" type="text/css" media="screen" />
    <link rel="stylesheet" href="admin/css/nivo-slider.css" type="text/css" media="screen" /> 

    <script type="text/javascript" src="admin/js/jquery.nivo.slider.js"></script>
    <script type="text/javascript">
        jQuery(document).ready(function() {
            $(window).load(function() {
                $('#slider').nivoSlider();
            });
        });
    </script>
<!--end slider -->

admin/connect.php

<?php
$host = "localhost";
$username = "root";
$password = "";
$db = "elearning";

mysql_connect($host,$username,$password) or die(mysql_error());
mysql_select_db($db);
?>

there is an fatal error at admin/connect.php said fatal error call to undefined mysql_connect() on line 7 admin/connect.php

PHP fatal error at admin/connect.php said fatal error call to undefined mysql_connect() on line 7 admin/connect.php

When working with sessions, you always have to put the session_start() before any output to the browser. Unfortunately, in this case, you've put session_start() after you called header.php, which does output to the browser...

...Also... you use mysql_ functions which are deprecated and might not work in the future. So try using msqli_ functions or PDO - Click Here

mean that i just put the session_start before the header.php?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.