2017-02-17 84 views
-1

的index.php为什么位置部分不工作?

$password = hash('sha256', $pass); // password hashing using SHA256 

    $res=mysql_query("SELECT * FROM users WHERE userEmail='$email'"); 
    $row=mysql_fetch_array($res); 
    $count = mysql_num_rows($res); // if uname/pass correct it returns        must be 1 row 

    if($count == 1 && $row['userPass']==$password) { 
    $_SESSION['user'] = $row['userId']; 
    $_SESSION['location'] = $row['userLocation']; 
    header("Location: home.php"); 
    } else { 
    $errMSG = "Incorrect Login"; 
    } 

Home.php

$query = "SELECT * FROM machines WHERE locatie=".$_SESSION['location']; 
$result = mysql_query($query); 

为什么这个不行? 我想不通为什么$_SESSION['locatie']部分不起作用? 我认为它与其他文件具有相同的值。

+0

您必须在标头 –

+3

不使用mysql函数后停止进一步处理。使用mysqli或pdo – Akintunde007

+0

所以代码将会是header(“Location:home.php”); die;试试这个 –

回答

1

你的mysql查询中有语法错误。

$query = "SELECT * FROM machines WHERE locatie='".$_SESSION['location']."'"; 
0

你想$_SESSION['location']值重定向后结转到home.php文件?

确保$row['location']有一个值,并且在两个页面上都调用了session_start()

0

尝试调试像这样

print_r($row); 

代码如果是,则再次做检查:

echo $row['userLocation']; 

你得到这个值? 然后,如果你想将价值为会话和书房重定向确保通过写session_start();你首先初始化会话和书房添加像

$_SESSION['location]= $row['userLocation]; 

价值,但要确保检查你得到设定会议前值? 如果你用print_r($row); 来更新你的代码,那么更好的办法就是解决这个问题,并且请停止使用SQL函数,因为它们被弃用,而不是使用mysqli和pdo。