Compare json data receive from android to database data in php -


i want receive json data android side. android side sending username , password in json php side. php code:

public function actiongetuserlogin()     {            // array json response           $response = array();            $conn=mysqli_connect("localhost","root","","db");          $user_login = "select * user" ;                      $query = mysqli_query ($conn, $user_login);                       while($results = mysqli_fetch_array ($query)){                             $user_name = $results['mobile_user_name'];                             $pass = $results['mobile_user_pass'];                             echo $user_name;                             echo "</br>";                             echo $pass;                             echo "</br>";                      }          //compare post data user existing username ,     password in database table   if($_post['username']==$user_name&&$_post['username']!=""&&$_post['password']==$pass&&$_post['password']!="")         {             //if match database record              $response["success"] = 1;               $response["message"] = "correct";         }else{             $response["success"] = 0;               $response["message"] = "wrong";         }          echo json_encode($response);         yii::app()->end();     } 

i error when test out method using url: http://localhost/myproject/index.php/user/getuserlogin

the error : undefined index: username

is gone wrong php when accepting json? there way display json data sent android?

public function actiongetuserlogin()     {    

add check before creating db connection

if(!isset($_post['username'],$_post['password']) || strlen($_post['password'])*strlen($_post['username'])==0){ header($_server['server_protocol']. ' 401 unauthorized'); return false; }           // array json response           $response = array(); 

i suggest implement datasource connection singleton

         $conn=mysqli_connect("localhost","root","","db"); 

         $user_login = "select * user" ;                      $query = mysqli_query ($conn, $user_login);                       while($results = mysqli_fetch_array ($query)){                             $user_name = $results['mobile_user_name'];                             $pass = $results['mobile_user_pass'];                             echo $user_name;                             echo "</br>";                             echo $pass;                             echo "</br>";                      }          //compare post data user existing username ,     password in database table 

if($_post['username']==$user_name&&$_post['username']!=""&&$_post['password']==$pass&&$_post['password']!="")             {                 //if match database record                  $response["success"] = 1;                   $response["message"] = "correct";             }else{                 $response["success"] = 0;                   $response["message"] = "wrong";             }              echo json_encode($response);             yii::app()->end();         } 

Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -