<?php
require 'connection.php';
$response = array();
$response_array = array();
$insert_query=0;
if(isset($_POST["username"]) && isset($_POST["password"]) && isset($_POST["phone"]))
{
$username = $_POST["username"];
$password = $_POST["password"];
$phone = $_POST["phone"];
$check_existing_user = mysql_query("select * from eh_users where username like '".$username."'");
if(mysql_num_rows($check_existing_user)==0)
{
$insert_query = mysql_query("INSERT INTO eh_users(username, password, phone) VALUES('$username','$password','$phone')");
if($insert_query==1)
{
$response["success"]=1;
$response["message"]="Insert Query Successful";
file_put_contents("myFile.txt", json_encode($response));
echo json_encode($response);
}
else
{
$response["success"]=0;
$response["message"]="Error : Query not successful";
echo json_encode($response);
}
}
}
?>
protected String doInBackground(String... params) { // TODO Auto-generated method stub
try
{
String url="http://www.iloveexpressions.com/eh/signUp.php";
httpclient = new DefaultHttpClient();
httppost = new HttpPost(url);
nameValuePairs = new ArrayList<NameValuePair>(3);
Log.d("Parameters ", username+" "+password+" "+phone);
nameValuePairs.add(new BasicNameValuePair("username", username.trim()));
nameValuePairs.add(new BasicNameValuePair("password", password.trim()));
nameValuePairs.add(new BasicNameValuePair("phone", phone.trim()));
Log.d("name value pairs", nameValuePairs.toString());
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response = httpclient.execute(httppost);
JSONObject json = jsonParser.getJSONFromUrl(url);
int success = json.getInt("success");
//JSONArray jArray = json.getJSONArray("success");
Log.d("Json object : ",success+"");
/*for(int i = 0; i < jArray.length(); i++ )
{
JSONObject c = jArray.getJSONObject(i);
String success = c.getString("success");
String message = c.getString("message");
Log.d("Sucess : ", success);
Log.d("Message : ", message);
}*/
}
the text file contains the right content {"success":1,"message":"Insert Query Successful"}
but i am not able to retrieve it in android