0

So here's my problem. I have a website and an android app for that. My users needs to be register in the website so I need not make a register page in the android part instead only the login page. But I got error in the login.php whenever I tried to run it on the browser to check if I'm getting the right response I got the error Undefined index: username and Undefined index: password. I don't know what is wrong.Below is the code for my login.php

<?php

include("config.php"); 
         $decoded = json_decode(file_get_contents("php://input")); 

        $username = $decoded -> {"username"};     
        $password = $decoded -> {"password"};
        $query = "SELECT u_id FROM pluma_user where password='$password' and username='$username'";     
        $result = mysql_query($query);  
        $obj = array();     
        $check = false;     

        while($row=mysql_fetch_assoc($result)){         
           $check = true;

           $obj["result"] = "ok"; 
           $obj["id"] = $row["u_id"]; 
        }   

        if($check == false){        
           $obj["result"] = "failed";
        }

        $obj1 = array(); 
        $obj1["result"] = "ok";

        echo json_encode($obj);   
        mysql_close();   
?>
4
  • @meda what do you mean showing the JSON? I'm retrieving the username and password using the JSON...
    – uhani_user
    Feb 18, 2014 at 1:34
  • Yes that json that you are retrieving
    – meda
    Feb 18, 2014 at 1:52
  • @meda sorry correct me if I'm wrong. But i'm retrieving the username and password residing in my database by the used of JSON and the problem is it shows error in the browser whenever the JSON response so I can't show you nothing because it says as the PROBLEM I stated is the undefined index.
    – uhani_user
    Feb 18, 2014 at 1:58
  • why are you even using a browser? the android is the client and the PHP is the server. Your application sends data to the server in JSON format. You can log that data and paste here. If you open this file in the browser of course these variables would be undefined because you wont make any request. You seem to be confuse about what I am asking you.
    – meda
    Feb 18, 2014 at 2:05

1 Answer 1

0

try this to find out the error

use

$result = mysql_query($query) or die (__LINE__." ".mysql_error());

so if there are any error at query will show the query line and the query error code and if want you can add __FILE__ but not recommended to use it for security reasons and should change mysql_error to mysql_errno after end the test

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.