0

我正在创建一个配置文件页面和一个登录页面,我在其中存储会话 ID,然后在配置文件中我检查是否 isset 但我得到的问题是系统总是显示错误消息并且我使用了 print_r($_SESSION ); 浏览器显示:

重要数据丢失Array ( [first_name] => [email] => )

这个错误怎么解决??????

登录.php

<?php
session_start();
error_reporting(E_ALL);
require_once('include/connect.php');
$message = ""; 
if(!empty($_POST['email']))
{

$email = $_POST['email'];
$pass = $_POST['pass'];

$email = strip_tags($email);
$pass = strip_tags($pass);
$email = mysql_real_escape_string($email);
$pass = mysql_real_escape_string($pass);
//$pass = md5($pass);

$sql=mysql_query( "SELECT user_id, email_address, first_name FROM user WHERE email_address='$email'AND password='$pass'LIMIT 1") or die("error in user table");
$login_check = mysql_num_rows($sql);

  if($login_check > 0)
  {
      $row = mysql_fetch_array($sql);

          $id = $row['user_id'];
          $_SESSION['user_id'] = $id;

          $firstname = $row['first_name'];
          $_SESSION['first_name']= $firstname;

          $email = $row['email_address'];
          $_SESSION['email_address']= $email;

          mysql_query("UPDATE user SET last_log_date=now() WHERE user_id='$id'");

          header("Location: profile.php");    
  }//close if 
  else
  {
      $message = "incorrect Email or Password!!";
      //exit();
  }
}//close if

?>  
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>RegisterPage</title>

<link href='http://fonts.googleapis.com/css?family=Oswald:400,300' rel='stylesheet' type='text/css' />
<link href='http://fonts.googleapis.com/css?family=Abel|Satisfy' rel='stylesheet' type='text/css' />
<link href="default.css" rel="stylesheet" type="text/css" media="all" />

</head>

<body>


       <div id="loginborder">
         <p  style="color:#FF0000" align="left"><?php print("$message") ?></p>

         <!--Login form where user submit his registered email and password-->
         <form action="login.php" method="post">
           email-address:<br />
           <input type="text" name="email" placeholder="Email Adress" />
           <br />
           <br />
           Password:<br />
           <input type="password" name="pass" placeholder="Password" />
           <br />
           <br />
           <input type="submit" name="login" value="Login" />
           <a href="register.php" style="position: absolute; top: 132px; left: 61px;"> <strong> Register</strong></a>
         </form>
       </div> 

配置文件.php

   <?php
session_start();
 require_once('include/connect.php'); 


if(isset($_GET['user_id']))
{
    $id=$_GET['user_id'];
    var_dump($id);

}
elseif(isset($_SESSION['user_id']))
{
    $id= $_SESSION['user_id'];
}

else
{
    print "Important  data  are missing";
    print_r($_SESSION);
    exit();

}

$sql = mysql_query("SELECT * FROM user  WHERE user_id='$id'") or die(mysql_error());
$row = mysql_fetch_array($sql);

   $firstname=$row['first_name'];
   $lastname=$row['last_name'];
   $birth_date=$row['birth_date'];
   $registered_date=$row['registered_date'];
   //***************for upload img*****************//
   $check_pic="members/$id/image01.jpg";
   $default_pic="members/0/image01.jpg";
   if(file_exists($check_pic))
   {
       $user_pic="<img src=\"$check_pic\"width=\"100px\"/>";
   }
   else
   {
       $user_pic="<img src=\"$default_pic\">";
   }
   echo $id, $firstname, $birth_date;
?>
4

2 回答 2

0

You need to changes several things

First : get first_name and email in your request

'SELECT user_id,email,first_name FROM user WHERE email_address='$email'AND password='$pass'LIMIT 1'

Second, remove while loop and do

$row = mysql_fetch_array($sql);

You are limiting to 1 result so no need to loop inside result

Change $id=$_SESSION['user_id']; to $_SESSION['user_id'] = $id;

Also, limit to 1 the result from profile and remove loop (user_id => UNIQUE => LIMIT 1)

于 2013-05-07T23:52:04.393 回答
0

您需要做的就是在所有检查完后将值存储在会话变量 [$_SESSION['username']] 中,然后使用会话中的值从 mysql 表中选择数据

- - - - - - - - - - - - - - - - - 例如 - - - - - - - --------------------------------------

在 login.php 上

if($login_check > 0)
{
  $_SESSION['email']=$email;//storing variable in SESSION
 header("Location: profile.php");    
}
else
{
  $message = "incorrect Email or Password!!";
  die();// kill the script
}

在 profile.php 上

<?php
session_start();// start session
require_once('include/connect.php'); //include connection file

$sql = mysql_query("SELECT * FROM user  WHERE email='(mysql_real_escape_string($_SESSION['email']))'") or die(mysql_error());
$row = mysql_fetch_array($sql);
// then just echo all the data you need
?>
于 2013-11-30T16:39:51.840 回答