Android错误的共享首选项

时间:2019-05-06 05:37:34

标签: php android pdo sharedpreferences

我希望您能帮助我理解有关我的代码的一些信息。

我正在创建一个User findOneByEmail(String email); android app表单的Login

我需要通过添加Registration编辑PHP文件。

我能够将PDOs文件用于PHP,但是有问题。

当用户PDO时,他的registersname被保存在surname中,并且每次访问怪物时都被保存。

问题在于,由于我通过添加SharedPreferences来修改PHP文件,因此,例如,如果我使用PDO访问,它将显示{{1}的名字和姓氏},如果我使用user1user2登录,user2总是向我显示user3的名称和姓氏。

为什么?

使用没有user4的{​​{1}}文件,它显示了我登录的用户的姓名和姓氏。

谁能解释为什么会这样?

没有PDO的Login.php

user2

使用PDO的Login.php

PHP

ParseContent.java

PDO

PreferenceHelperRistoratore

<?php

   if($_SERVER['REQUEST_METHOD']=='POST'){
  // echo $_SERVER["DOCUMENT_ROOT"];  // /home1/demonuts/public_html
//including the database connection file
       include_once("config2.php");

    $idAKr = $_POST['idAKr'];
    $cell = $_POST['cellulare'];

     if( $idAKr == '' || $cell == '' ){
            echo json_encode(array( "statusr" => "false","message" => "Inserisci numero di telefono!") );
     }else{
        $query= "SELECT * FROM Ristoratori WHERE cellulare='$cell'";
            $result= mysqli_query($con, $query);

            if(mysqli_num_rows($result) > 0){  
             $query= "SELECT * FROM Ristoratori WHERE cellulare='$cell'";
                         $result= mysqli_query($con, $query);
                     $emparray = array();
                         if(mysqli_num_rows($result) > 0){  
                         while ($row = mysqli_fetch_assoc($result)) {
                                     $emparray[] = $row;
                                   }
                         }
               echo json_encode(array( "statusr" => "truer","message" => "Accesso eseguito", "datar" => $emparray) );
            }else{ 
                echo json_encode(array( "statusr" => "false","message" => "Numero di telefono sbagliato!") );
            }
             mysqli_close($con);
     }
    } else{
            echo json_encode(array( "statusr" => "false","message" => "Errore, riprova!") );
    }
?>

Login.java

<?php

   if($_SERVER['REQUEST_METHOD']=='POST'){
  // echo $_SERVER["DOCUMENT_ROOT"];  // /home1/demonuts/public_html
//including the database connection file

require_once('db.php');

    $idAKr = $_POST['idAKr'];
    $cell = $_POST['cellulare'];

     if( $idAKr == '' || $cell == '' ){
            echo json_encode(array( "statusr" => "false","message" => "Inserisci numero di telefono!") );
     }else{
         $conn=$dbh->prepare("SELECT cellulare FROM Ristoratori WHERE cellulare=?");
         $conn->bindParam(1,$cell);
         $conn->execute();

         if($conn->rowCount() !==0){

         $conn2=$dbh->prepare("SELECT COUNT(cellulare) FROM Ristoratori WHERE cellulare=?");
         $conn2->bindParam(1,$cell);
         $conn2->execute();
         $data_exists = ($conn2->fetchColumn());
         $emparray = array();

         if($data_exists > 0){

             $emparray = $conn->fetchAll(PDO::FETCH_ASSOC);


         }
         echo json_encode(array( "statusr" => "truer","message" => "Accesso eseguito", "datar" => $emparray) );

        }  else{ 
                echo json_encode(array( "statusr" => "false","message" => "Numero di telefono sbagliato!") );
            }  
     }
     $dbh = null;
    } else{
            echo json_encode(array( "statusr" => "false","message" => "Errore, riprova!") );
    }
?>

0 个答案:

没有答案