$ _SESSION或session_start()

时间:2015-02-15 23:11:38

标签: php mysql session pdo

我有以下问题:

我在我的数据库上恢复了几个信息,并且我成功地在Android手机上的TextView中显示它。问题是当我做MySQL请求时,我将邮件与“a@a.a”进行比较。

$query = $handler->query('SELECT name, firstName, mail, nationality, city FROM login WHERE mail = "a@a.a"');

我尝试与$ _SESSION ['mail']进行比较,但是使用这种方法,我有任何结果。

$query = $handler->query('SELECT name, firstName, mail, nationality, city FROM login WHERE mail = "'.$email.'"');

问题可能在于session_start()或$ _SESSION [],但我找不到,所以如果你可以帮助我!!

我在下面写了不同的代码:

的config.php

<?php
try{
$handler = new PDO('mysql:host=localhost;dbname=project', 'root', 'xxxx');
$handler->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

 session_start();
 $email = $_SESSION['mail'];
 echo "$email + toto";

 }catch(Exception $e){
   echo $e->getMessage();
   die();
}
?>

的login.php

<?php
$connect = mysql_connect('localhost','root','aragorn11') or die ("erreur de connexion");
mysql_select_db('project',$connect) or die ("erreur de connexion base");
session_start();
$email=$_SESSION['mail'];

// Recup elem to make the login_connection
$password=$_POST["password"];
$mail=$_POST["mail"];

if (!empty($_POST)) {
if (empty($_POST['mail']) || empty($_POST['password'])) {
// Create some data that will be the JSON response 
      $response["success"] = 0;
      $response["message"] = "One or both of the fields are empty .";

      //die is used to kill the page, will not let the code below to be executed. It will also
      //display the parameter, that is the json data which our android application will parse to be //shown to the users
      die(json_encode($response));
  }
 $query = " SELECT * FROM login WHERE mail = '$mail'and password='$password'";

   $sql1=mysql_query($query);
$row = mysql_fetch_array($sql1);
if (!empty($row)) {
   $response["success"] = 1;
      $response["message"] = "You have been sucessfully login";
  $_SESSION['mail'] = $mail;
die(json_encode($response));
}
else{

$response["success"] = 0;
      $response["message"] = "invalid mail or password ";
die(json_encode($response));
 }   
}
else{

 $response["success"] = 0;
      $response["message"] = " One or both of the fields are empty ";
die(json_encode($response));
}
mysql_close();
?>

和info.php:

<?php
include ('config.php');

$query = $handler->query('SELECT name, firstName, mail, nationality, city FROM login WHERE mail = "'.$email.'"');
$records = array();
$records = $query->fetchAll(PDO::FETCH_ASSOC);
$json['login'] = $records;
echo json_encode($json);
?>

非常感谢你的帮助。

0 个答案:

没有答案