samedi 14 février 2015

Decode Json data into PHP Variables


Im sending my data to PHP file like this using angularJS ajax


{ username: "someusername", password: "somepassword" }


previously i used something like this to send data



var vars = "username="+fn+"&password="+ln;


but since angular sending data like JSON. i want to decode into PHP variables.


here my PHP code



if(isset($_POST['username']) && isset($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
}

$sql = "SELECT * FROM member WHERE username = '$username' AND password = '$password'";


what i tried to do is something like this



$array = json_decode(file_get_contents('php://input'))
$username = $array->username;
$password = $array->password;


$sql = "SELECT * FROM member WHERE username = '$username' AND password = '$password'";


but not sure how to do it. also no idea about what happens in this section 'file_get_contents('php://input')' im sending data from local computer to internet server PHP file (Cross Domain)





Aucun commentaire:

Enregistrer un commentaire