Note that there are some explanatory texts on larger screens.

plurals
  1. POi am unable to decode json object in php
    primarykey
    data
    text
    <p>here is my java code and it makes an http request and send json object to php script.</p> <p>login.java</p> <pre><code> String username = jTextField1.getText(); String password = jPasswordField1.getText(); JSONObject obj = new JSONObject(); obj.put("username", username); obj.put("password", password); //JSONArray list = new JSONArray(); //list.add(username); //list.add(password); //obj.put("logindata", list); try { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response; HttpPost httppost = new HttpPost("http://localhost/kolitha/json_test/index.php"); StringEntity se = new StringEntity("myjson" + obj.toString()); httppost.setEntity(se); System.out.print(se); httppost.setHeader("Accept", "application/json"); httppost.setHeader("Content-type", "application/json"); System.out.println(obj.toString()); //response = httpclient.execute(httppost); HttpGet httpget = new HttpGet("http://localhost/kolitha/json_test/index.php"); response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); System.out.println(EntityUtils.toString(entity)); } catch (Exception e) { e.printStackTrace(); System.out.print("Cannot establish connection!"); } </code></pre> <p>this is my index.php script and i am unable to extract username and password from the json object.</p> <p>index.php</p> <pre><code>$obj = json_decode(file_get_contents('php://input')); $username=$obj-&gt;{'username'}; $password=$obj-&gt;{'password'}; $connect=mysql_connect('localhost', 'root', ''); IF (!$connect){ die ('Failed Connecting to Database: ' . mysql_error());} $d = mysql_select_db("kolitha_json_test"); if(!$d){ echo "db not selected";} $sql="SELECT * FROM login WHERE username='$username' AND password='$password' "; $result=mysql_query($sql) or die (mysql_error()); $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1) { echo "true"; } else { echo "false"; } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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