I know little bit of php-mysql and web programming. For my project work, i made one login module, it contains two pages but it has some errors. I use WAMP for project, whenever i feed data and press login it does not go to profile.php page and session does not start. It show same page(login.php) after Login Button Pressed From last two days i was searching for this error but i cant solve it. My project have other several pages. Here is my code.

login.php

<html>
<head>
<link rel="stylesheet" type="text/css" href="text.css" ></link>
<title>Login</title>
</head>

<body>
<div class="container" >
<div id="header" style="text-align: center;" >
<table width="500" align="center">
    <tr >
    <img src="logo.jpg"/>
    </tr>
</table>
</div>

<div>
<table class="form" align="center"  style="height:200px;padding-left:30px;float-align:center;margin-left=20px;margin-top:40px;margin-bottom:20px;text-align:;padding-left:20px;">
<form action="loginproc.php" method="POST">
<tr>
    <td align="center"colspan="780px" >
    <h3 style="font-family:Calibri; font-size: 22pt;font-weight: bold; color:#3B8C8C;text-align: center;">LOGIN</h3></td>
</tr>
<tr>
    <td>Email ID</td>
    <td><input type="email" name="emailid" maxlength="50" /></td>
</tr>
<tr>
    <td>Password</td>
    <td><input type="password" name="pwd" /></td>
</tr>
<tr>
    <td colspan="3" align="center" style="margin-bottom:20px;">
    <input type="submit" name="submit" class="button" value="Login" style="margin-bottom:20px;margin-top:20px;"/>
    <input type="reset" name="reset" class="button" value="Reset" style="margin-bottom:20px;margin-top:20px;"/>
</tr>   
</form></table></div>
</div>
</body>

</html>

loginproc.php

<?php
if(isset($_REQUEST['submit']))
{
$server="localhost";
$user="root";
$password="";
$db="utility";
$con = mysql_connect($server,$user,$password);
if(!$con) 
{
    die("Cannot Connect".mysql_error());
}
else
    {
    if(!mysql_select_db($db,$con))
    {
    header('Location: login.php');
    }
    else
    {
    $email = isset($_POST['emailid'])? $_POST['emailid']:"";
    $email = mysql_real_escape_string($email);

    $password = isset($_POST['pwd'])? $_POST['pwd']:"";
    $password = mysql_real_escape_string($password);

    $access = "SELECT * FROM register WHERE (email = '$email') AND (password = '$password')";
    $access = mysql_query($access);
    $accessrow = mysql_num_rows($access);

    if($accessrow == 1)
    {
        include('session.php');
        $_SESSION['email'] = $email;
        header('Location: profile.php');
    }
    else
    {
        header('Location: home.php');   
    }
    mysql_close($con);
    }
}
}
?>

You need to include session_start() at the top of loginproc.php

type exit after all headers to avoid belwo code to excute;

header('Location: profile.php');
exit;

are you sure your db connection is working

try adding some debugging

if(!mysql_select_db($db,$con))
{
header('Location: login.php?selectDB=failed');
}
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.