android - not getting the json data in php -


i creating android application , submit user details android application php @ server side json.but @ server side not getting json data.at server side php json comes android application seems null.i using post method this.i know post method code wrong in php @ server side.but have no idea solve this. please me.thanks in advance. here php code getting json. everytime same message required fields missing.

<?php  /* * following code create new user row * user details read http post request */  // array json response $response = array(); print_r($_post); // check required fields if (isset($_post['firstname']) && isset($_post['lastname']) && isset($_post['username'])     && isset($_post['email']) && isset($_post['password']) && isset($_post['country']) &&     isset($_post['mobile'])) { echo('bhargavi'); $firstname = $_post['firstname']; $lastname = $_post['lastname']; $username = $_post['username']; $email = $_post['email']; $password = $_post['password']; $country = $_post['country']; $mobile = $_post['mobile'];  // include db connect class require_once __dir__ . '/db_connect.php';  // connecting db $db = new db_connect();  // mysql inserting new row $result = mysql_query("insert     users(firstname,lastname,username,email,password,country,mobile)     values('$firstname','$lastname','$username','$email','$password','$country','$mobile')");  // check if row inserted or not if ($result) {     // inserted database     $response["success"] = 1;     $response["message"] = "user registered.";      // echoing json response     echo json_encode($response); } else {     // failed insert row     $response["success"] = 0;     $response["message"] = "oops! error occurred.";      // echoing json response     echo json_encode($response); } } else { // required field missing $response["success"] = 0; $response["message"] = "required field(s) missing";  // echoing json response echo json_encode($response); } ?> 

probably should decode json string before checking $_post['firstname'] etc...

let's send app string called data. on php should that:

$data = json_decode($_post['data']); , check if $data contains data neeed doing: if (isset($data->firstname) && isset($data->lastname) etc...){ ... ... } 

if can give advice better if check data integrity directly app instead of doing on server, give chance spare server resources...

as jay blanchard mentioned don't use mysql or you'll exposed mysql injection...


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -