Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid to JSON to PHP to MySQL
    primarykey
    data
    text
    <p>I'm trying to send a few STRING variables from android to PHP as JSON. I accomplished this using one of the guides on the internet but unfortunately its not working and i'm unable to solve it using other similar questions on StackOverflow.</p> <p>Here's my android code :-</p> <pre><code>JSONObject jsonObject= new JSONObject(); JSONArray jsonArray=new JSONArray(); public class sendData extends AsyncTask&lt;String, String, Void&gt; { @Override protected Void doInBackground(String... params) { HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost("http://bdp.site40.net/sendRegData.php"); try { HttpEntity httpEntity = new StringEntity(jsonArray.toString()); httpPost.setEntity(httpEntity); httpClient.execute(httpPost); } catch (IOException e) { } return null; } } public void onClickSubmitButton(View view) throws JSONException { jsonObject.put("name",name); jsonObject.put("blood",blood); jsonObject.put("cell",cell); jsonObject.put("email", email); jsonObject.put("address",address); jsonObject.put("country",country); jsonObject.put("state",state); jsonObject.put("city",city); jsonArray.put(jsonObject); new sendData().execute(); } </code></pre> <p>And here is my PHP code :-</p> <pre><code>&lt;?php $json = file_get_contents("php://input"); $data = json_decode($json); $name = $data[0]-&gt;name; $blood = $data[0]-&gt;blood; $cell = $data[0]-&gt;cell; $email = $data[0]-&gt;email; $address = $data[0]-&gt;address; $country = $data[0]-&gt;country; $state = $data[0]-&gt;state; $city = $data[0]-&gt;city; $con = mysql_connect("","","") or die(mysqli_connect_error()); $db = mysql_select_db("",$con) or die(mysqli_connect_error()); mysql_query("INSERT INTO Donors(Name,Blood,Mobile,E-Mail,Address,Country,State,City)VALUES('$name','$blood','$cell','$email','$address','$country','$state','$city')"); ?&gt; </code></pre> <p>After experimenting a little I have narrowed it down to the fact that the problem lies in which i SEND data to the PHP script AND/OR the way data is RECIEVED by the PHP script. Can anyone please look for the problem and correct it? Thank You!</p> <p>Points to Note:</p> <ol> <li>I have removed MySQL username,password,database name and host for privacy(obviously).</li> <li>All the 8 variables are in String format.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload