Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8127597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T07:35:13+00:00 2026-06-06T07:35:13+00:00

Here my code, I need to insert into mysql database I have mysql,php,android 1)

  • 0

Here my code, I need to insert into mysql database I have mysql,php,android

1) The problem i have, i need a successful result to my php so that I can be able to insert using android.so my code for php:

2) The table I’m using has a foreign key : Provinces_idProvinces.

 $result = mysql_query("INSERT INTO property( Pname, P_Price,P_Desc,P_City, P_Size,P_Rooms, P_garage, P_Address, P_Long, P_Lat, Provinces_idProvinces)  
VALUES('$_POST[Pname]',$_POST[P_Price],'$_POST[P_Desc]','$_POST[P_City]','$_POST[P_Size]','$_POST[P_Rooms]',$_POST[P_garage],'$_POST[P_Address]',$_POST[P_Long],$_POST[P_Lat],$_POST[Provinces_idProvinces])");

 if ($result) {
        // successfully inserted into database
        $response["success"] = 1;
        $response["message"] = $result ;

        // echoing JSON response
        echo json_encode($response);
    } else {
        // failed to insert row
        $response["success"] = 0;
        $response["message"] = "Oops! An error occurred.";

        echo $response["success"];

        // echoing JSON response
        echo json_encode($response);
    }

And my class which I pass parameters but it giving me an error :

List<NameValuePair> params = new ArrayList<NameValuePair>();
          Log.d("Parameters","1");
          params.add(new BasicNameValuePair("Pname",Pname));
          params.add(new BasicNameValuePair("P_Price",Prices));        
          params.add(new BasicNameValuePair("P_Desc",Desc));
          params.add(new BasicNameValuePair("P_City",city));
          params.add(new BasicNameValuePair("P_Size",Size));
          params.add(new BasicNameValuePair("P_Rooms",bedNumber));
          params.add(new BasicNameValuePair("P_garage",Garnums));
          params.add(new BasicNameValuePair("P_Address",Address));
          params.add(new BasicNameValuePair("P_Long",longertude));
          params.add(new BasicNameValuePair("P_Lat",lattitude));
          params.add(new BasicNameValuePair("Provinces_idProvinces",Provnums));

          Log.d("Json","obj");
       // getting JSON Object
          // Note that create product url accepts POST method

          JSONObject json = jsonParser.makeHttpRequest(save_prop,
                  "POST", params);
          // check log cat fro response
          Log.d("Create Response", json.toString());

Which I’m getting an error in JSON because of the value 0, which is returned by php,
I DO NOT KNOW HOW TO SOLVE THIS PROBLEM

And here my logCat :

06-25 19:36:40.175: E/JSON Parser(2261): Error parsing data org.json.JSONException: Value 0 of type java.lang.Integer cannot be converted to JSONObject
06-25 19:36:40.175: W/dalvikvm(2261): threadid=10: thread exiting with uncaught exception (group=0x40014760)
06-25 19:36:40.236: E/AndroidRuntime(2261): FATAL EXCEPTION: AsyncTask #1
06-25 19:36:40.236: E/AndroidRuntime(2261): java.lang.RuntimeException: An error occured while executing doInBackground()
06-25 19:36:40.236: E/AndroidRuntime(2261):     at android.os.AsyncTask$3.done(AsyncTask.java:266)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T07:35:14+00:00Added an answer on June 6, 2026 at 7:35 am

    EDIT: Simply just remove echo $response["success"];.

    You shouldn’t print out the results like the way you have. I assume this is what the results would look like when you hit the server with that request…

    0{"results":"..."}
    

    You’re getting this error because the result (shown above) is being consumed as a JSON Object on the Android side. The results above IS NOT in a valid JSON format thus an exception is thrown. So my suggestion is to rework your PHP to return results that look like…

    {"success":0,"results":"..."}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need help with PHP Mysql code to insert multiple select data into database. With
There is a weird code here that I need to make work.. can you
I have a MySQL database/table set up and a .php file online that inserts
I have the following code: <?php include('settings.php'); //Here I have my connection string $result
I have an application I need to analyze. I have the source code here.
I have a script that polls a MySQL database (Nagios, specifically) for the date/time
I need help with this code, it doesent insert the values to my database.
I have a mySQL database and I have a Perl script that connects to
MY PLATFORM: PHP & mySQL WHAT I HAVE HERE: I have 4 tables, namely,
In my example code below, you can see that I have been trying to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.