2012-09-20 91 views
2

我知道一点点的php-mysql和web编程。对于我的项目工作,我做了一个登录模块,它包含两个页面,但它有一些错误。我使用WAMP进行项目,只要我提供数据并按下登录,它就不会进入profile.php页面,并且会话不会启动。它显示登录按钮后按相同的页面(login.php)最近两天我正在寻找这个错误,但我无法解决它。我的项目有其他几页。这是我的代码。

的login.phpphp登录模块不起作用

<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); 
    } 
} 
} 
?> 
+0

既然你说,它显示“的login.php”,这不是应显示两个页面中的一个,我说你的重定向不工作。这似乎是可能的,如果连接失败(或者如果你的代码是坏的)。 –

+0

雅我有同样的疑问,重定向不起作用,但在注册模块中使用相同样式的代码,并且它完美地工作。代码中的会话管理是否有错误? –

+0

如果用户没有登录,home.php是否会重定向到login.php? –

回答

0

在你的代码贴出来,你有一个领先的空间,这将防止从开始以来的会话cookie具有会话在任何输出之前设置。

*SPACE*<?php 
if(isset($_REQUEST['submit'])) 
{ 

是这个空间在您的文章有误,或者是你真的在你的login.php文件?

+0

对不起,这是我的文章中的错误,实际的文件不包含空间 –

+0

您的PHP错误日志有任何错误,以响应您的表单提交? – jimp

0

检查数据库连接和这一行if(!mysql_select_db($db,$con)) 就这么你知道,使用MySQLi或PDO_MySQL代替MySQL作为它的弃用。

+0

我检查了数据库连接其工作正常。注册模块(register.php&dataentry.php)使用相同类型的代码。现在注册模块工作正常,Data成功添加到数据库。 –

+0

尝试更改'include('session.php');'包含'session.php';'' –

0

你的代码在这里

if(!mysql_select_db($db,$con)) 
{ 
header('Location: login.php'); 
} 

执行可能给定的数据库不存在,这就是为什么login.php页面showing.Check数据库。

并尝试妥善安排您的HTML代码。您在Table内使用Form

它应该是这样的

<form> 
    <table> 
     // your code.. 
    </table> 
</form>