php - Another Error parsing data org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject -
I'm pulling my hair on it, I can write in a database with the same code (hopefully this INSERT INTO command) but it does not work.
PHP:
$ Id = $ _POST ['id']; // $ id = '000000000002'; $ Yuri = $ _POST ['Yuri']; // $ uri = 'sdfgdsfg'; {$ Stmt = $ conn- & gt; Try ("Users set photo PHOTO =? WHERE ID =?"); $ Stmt- & gt; Execute (array ($ uri, $ id)); $ Response ["success"] = 1; } Hold (PDOException $ e) {echo 'error:' $ E & gt; GetMessage (); $ Response ["success"] = 0; } Echo json_encode ($ response);
Java:
Try {paramsC = new array list & lt; NameValuePair & gt; (); ParamsC.add (New BasicNameValuePair ("id", userid)); ParamsC.add (new binary namewallpayer ("Yuri", "Hello")); JSONParser jsonParser; JsonParser = new JSONParser (); JSONObject json = jsonParser.makeHttpRequest (set_profile_photo_uri, "post", params c); Try {int success = json.getInt ("Success"); // error tells this line that if (success == 1) {// successfully updated log d. ("Signup", "success"); } And {Log D. ("Signup", "unsuccessful"); }} Catch (JSOXECTION E) {//Log.e("L_log_tag "," Error Parsing Data "+ E.Streatin ()); //Log.e("log_tag "," Failed Data was: \ n "); }} Hold (exception e) {e.printStackTrace (); }
I get an error:
02-17 21: 37: 45.104: E / Jasonan parser (21276): data parsing error org. Json .JSONException: Value & lt ;; DOCTYPE type java.lang.String can not be converted to JSONObject 02-17 21: 37: 45.104: w / System.err (21276): java.lang.NullPointerException 02-17 21:37: 45.124: W / System Er (21276): com.example.myapp.TabFragment1 $ 8.onClick (TabFragment1.java:171)
However, this code works, but why ?: Try $ stmt = $ conn- & gt; (Username (USERNAME, password, NAME, EMAIL, GENDER, DATEOFREG_PHONE, DATEOFREG_SV) Prices ("INSERT INSERT"): Username, Password: Name, Email ,: gender, dateofreg_phone, dateofreg_sv); $ Query_params = array (': username' = & gt; $ username, ': password' = & gt; $ password, ': name' = & gt; $ name, ': email' = & gt; $ email, : $ Gender_name = $ dateofreg_phone, 'dateofreg_sv' = & gt; $ dateofreg_sv); $ stmt- & gt; execution ($ query_params); $ response [gender: 'gender' = & Gt; $ gender; 'dateofreg_phone' Success "] = 1;} hold (PDOException $ e) {echo 'error:' $ e & quot; getMessage (); $ response [" success "] = 0;} echo json_encode ($ response);
When I enter the browser PHP code works fine.
An answer from the comments to close this question To: Make sure you send a query to a URL.
Comments
Post a Comment