2016-06-22 51 views
-1

谁可以帮我,这是代码:无法保存数据库值会话PHP

<?php 

session_start(); 

if(isset($_SESSION['user_id'])){ 
    header('Location: index.php'); 
} 

require 'database.php'; 
$error=''; 

if(!empty($_POST['username']) && !empty($_POST['password'])): 

$records = $conn->prepare('SELECT id,name,surname,username,password FROM users WHERE username =:username'); 

    $records->bindValue(':username', $_POST['username']); 
    $records->execute(); 
    $results = $records->fetch(PDO::FETCH_ASSOC); 


    if(count($results) > 0 && password_verify($_POST['password'], $results['password'])){ 
     $_SESSION['user_id'] = $results['id']; 
     $_SEESION['user_name'] = $results['name']; 
     $_SEESION['user_surname'] = $results['surname']; 
     header('Location: index.php'); 
    }else{ 
     $error = 'Na vjen keq, username ose passowrd jane gabim !!'; 
    } 

endif; 
?> 

会话user_id是正常保存,我可以使用它,但其他两会user_name和user_surname是不beign保存,当我尝试使用他们,我得到一个错误说未定义“USER_NAME”和“user_surname”

+0

请分享埃罗你正在得到。 –

回答

3

上有$_SEESION['user_name']错字和$_SEESION['user_surname']将其更改为:

$_SESSION['user_name'] = $results['name']; 
$_SESSION['user_surname'] = $results['surname'];