php - Why is JSON returning null? -


i 'm making application handles registration.i use php mysql.when register ,the details entered correctly inserted table when echoed response returns null message.

here picture

enter image description here

when in application null json feed can't proceed further.

what want is message should either success or failure.i don't know whats wong code.here php code:

<?php include_once './dbconnect.php'; function createnewprediction() {       $response = array();     $name = $_post["name"];     $college =  $_post["college"];     $mobile =  ($_post["mobile_no_"]);     var_dump( $mobile);      $email =  $_post["email"];             $db = new dbconnect();     // mysql query    mysql_query('set character set utf8');     $query = "insert register(name,college,mobile,email)     values('{$name}','{$college}','{$mobile}','{$email}')";     $result = mysql_query($query) or die(mysql_error());     if ($result) {         $response["error"] = false;         $response["message"] = "registered successfully!!";     } else {         $response["error"] = true;         $response["message"] = "registration unsuccessfull!!";     }    // echo json response    echo phpversion();    echo json_last_error_msg();  echo json_encode($response); } createnewprediction(); ?> 

as can see have tried 'json_last_error_msg()' gives me no error.i don't understand lies fault.

hope these materials enough assessment of question.please me out?

edit here java code making calls , receiving json. let me elaborate problem.in below code 'line' i'm using pass response json null.

here have tried in console:

  1. i have tried 'reader.tostring()', gave me nothing

2.i have tried 'is.tostring()',strangely gave me message 'success' in console.

so problem seems in code.i 'm sorry said problem php code.i 'm beginner please kindly understand me.please help.

jsonparser

package com.defcomdevs.invento16; import android.util.log;  import java.io.bufferedreader; import java.io.ioexception; import java.io.inputstream; import java.io.inputstreamreader; import java.io.unsupportedencodingexception; import java.util.list;  import org.apache.http.httpentity; import org.apache.http.httpresponse; import org.apache.http.namevaluepair; import org.apache.http.client.clientprotocolexception; import org.apache.http.client.entity.urlencodedformentity; import org.apache.http.client.methods.httpget; import org.apache.http.client.methods.httppost; import org.apache.http.client.utils.urlencodedutils; import org.apache.http.impl.client.defaulthttpclient; import org.json.jsonexception; import org.json.jsonobject;   /**  * created midhun on 18/11/15. */ public class jsonparser {  static  inputstream is= null;  //input stream object hold incoming data static  jsonobject obj=null; static string json="";  //constructor public jsonparser(){  }   //functionn json url //by making http post or methods public jsonobject makehttprequest(string url, string method,list<namevaluepair> params){      //making http request     try{          //check request method         if (method== "post"){              //request method post             //call default http client             defaulthttpclient httpclient = new defaulthttpclient();             httppost httppost = new httppost(url);             httppost.setentity(new urlencodedformentity(params));              httpresponse httpresponse = httpclient.execute(httppost);             httpentity httpentity = httpresponse.getentity();             is= httpentity.getcontent();         }else if(method == "get"){             // request method             defaulthttpclient httpclient = new defaulthttpclient();             string paramstring = urlencodedutils.format(params, "utf-8");             url += "?" + paramstring;             httpget httpget = new httpget(url);              httpresponse httpresponse = httpclient.execute(httpget);             httpentity httpentity = httpresponse.getentity();             = httpentity.getcontent();         }     }catch (unsupportedencodingexception e){         e.printstacktrace();     }catch (clientprotocolexception e){         e.printstacktrace();     }     catch (ioexception e){         e.printstacktrace();     }     try {         bufferedreader reader= new bufferedreader(new inputstreamreader(is,"iso-8859-1"),8);         stringbuilder sb = new stringbuilder();         string line= null;         while((line = reader.readline())!=null){             sb.append(line +"\n");         }         is.close();         json = sb.tostring();      }catch (exception e){         log.e("buffer error", "error converting result " + e.tostring());     }      //try parse string json object      try{         obj=new jsonobject(json);     }catch (jsonexception e){         e.printstacktrace();     }     return obj; }  public static  string returnjson(){     return json; } } 

you out put 3 echo's

 echo phpversion();     echo json_last_error_msg();      echo json_encode($response); 

and var_dump( $mobile);


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -