如下所示,我有一个登录页面,它将根据结果返回索引。当我来到这个页面它什么也没做。会话等注册和登录,但我必须手动重新进入我自己的页面?
<?php
session_start();
include("connect_db.php");
$tbl_name="users";
$email=$_POST['email'];
$pass=$_POST['pass'];
$sql="SELECT * FROM $tbl_name WHERE email='$email' and pass='$pass'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1){
while($row = mysql_fetch_array($result))
$username=$row['username'];
$_SESSION['username']=$username;
header('location: index.php?login=yes');
}else {
header('location: index.php?login=no');
}
?>
答案 0 :(得分:0)
尝试如下:
<?php
session_start();
include("connect_db.php");
$tbl_name="users";
$email=$_POST['email'];
$pass=$_POST['pass'];
$sql="SELECT * FROM $tbl_name WHERE email='$email' and pass='$pass'";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
if($count==1)
{
while($row = mysql_fetch_array($result))
{
$username=$row['username'];
$_SESSION['username']=$username;
}
header('location: index.php?login=yes');
}
else {
header('location: index.php?login=no');
}
?>