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 7599127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:35:02+00:00 2026-05-30T22:35:02+00:00

I want to save data into a server. This is my simple php code:

  • 0

I want to save data into a server. This is my simple php code:

<?php
require('Zend\Db.php');
require('Zend\Db\Exception.php');
function sendResponse($status, $payload)
{
$responseCodeList = array(
    200 => 'OK',
    201 => 'Created',
    204 => 'No Content',
    301 => 'Moved Permanently',
    400 => 'Bad Request',
    404 => 'Not Found',
    410 => 'Gone',
    501 => 'Not Implemented',
);

header('HTTP/1.1 ' . $status . ' ' . $responseCodeList[$status]);
header('Content-Type: text/plain');
echo (string) $payload;
}
try {

$db = Zend_Db::factory('Oracle', array(
    'host'       => '10.234.152.6',
    'username'   => 'DMHR',
    'password'   => '',
    'dbname'     => '//10.234.152.6/SATHRIS',
));
} catch (Zend_Db_Exception $e) {
echo sendResponse(200,'100|Database Error');
exit;
}

$method = $_SERVER['REQUEST_METHOD'];

$payload = '';

if ($method = 'GET') {
   $data = $_GET;
try {
     $array_data = array(
        'AD_KODE_TOKO' => $data['kode_toko'],
        'AD_NAMA' => $data['nama'];
        'AD_ALAMAT' => $data['alamat'],
        'AD_KODE_POS' => $data['kode_pos'],
        'AD_NO_TELP' => $data['no_telp'],
        'AD_LONGITUDE' => $data['longitude'],
        'AD_LATITUDE' => $data['latitude'],
        'AD_PERUSAHAAN' => $data['perusahaan'],
    );

    $db->beginTransaction();
    $db->insert('ANDROID_DATA', $array_data);
    $db->commit();
    $payload = 'SUCCESS';
} catch(Zend_Db_Exception $e) {
    $payload = 'FAILURE';
    echo "<pre>";
    print_r($e);
    echo "</pre>";
}

}

echo sendResponse(200, $payload);

…and this is my main Activity to save into the server:

private EditText etkdstore;
private EditText etnama;
private EditText etalamat;
private EditText etkdpos;
private EditText etnotelp;
private EditText etlng;
private EditText etlat;
private EditText etperush;
//private TextView idgambar;

private Button save;

private String url = "10.234.152.6/upload_get.php";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    etkdstore = (EditText)findViewById(R.id.kdstore);
    etnama = (EditText)findViewById(R.id.nama);
    etalamat = (EditText)findViewById(R.id.alamat);
    etkdpos = (EditText)findViewById(R.id.kdpos);
    etnotelp = (EditText)findViewById(R.id.telp);
    etlng = (EditText)findViewById(R.id.lng);
    etlat = (EditText)findViewById(R.id.lat);
    etperush = (EditText)findViewById(R.id.perush);
   // idgambar = (TextView)findViewById(R.id.gambar);

    save = (Button)findViewById(R.id.save);

    save.setOnClickListener(new Button.OnClickListener() {
            //@Override
    public void onClick(View v) {
    try {
    // setiap parameter yang akan dikirim melalui http
    // harus encode agar
    // dapat terbaca dengan baik oleh server
    String kdstore = URLEncoder.encode(etkdstore.getText().toString(), "utf-8");
    String nama = URLEncoder.encode(etnama.getText().toString(), "utf-8");
    String alamat = URLEncoder.encode(etalamat.getText().toString(), "utf-8");
    String kdpos = URLEncoder.encode(etkdpos.getText().toString(), "utf-8");
    String notelp = URLEncoder.encode(etnotelp.getText().toString(), "utf-8");
    String lng = URLEncoder.encode(etlng.getText().toString(), "utf-8");
    String lat = URLEncoder.encode(etlat.getText().toString(), "utf-8");
    String perush = URLEncoder.encode(etperush.getText().toString(), "utf-8");
    //String gambar = URLEncoder.encode(idgambar.getText().toString(), "utf-8");
    url += "?kode_toko=" + kdstore + "&&nama" + nama + "&&alamat=" + alamat + "&&kode_pos=" + kdpos +
    "&&no_telp=" + notelp + "&&longitude=" + lng + "&&latitude=" + lat + "&&perusahaan=" + perush;
    getRequest(url);
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        }
        }
    });
}
public void getRequest(String Url) {

            Toast.makeText(this, "Tambah Data " + Url + " ", Toast.LENGTH_SHORT).show();
            HttpClient client = new DefaultHttpClient();
            HttpGet request = new HttpGet(url);
            try {
                HttpResponse response = client.execute(request);
                Toast.makeText(this, "Tambah Data " + request(response) + " ",Toast.LENGTH_SHORT).show();
            } catch (Exception ex) {
                Toast.makeText(this, "Tambah Data Gagal !", Toast.LENGTH_SHORT).show();
            }
        }
public static String request(HttpResponse response) {

            String result = "";
            try {
                InputStream in = response.getEntity().getContent();
                BufferedReader reader = new BufferedReader(
                        new InputStreamReader(in));
                StringBuilder str = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    str.append(line + "\n");
                }
                in.close();
                result = str.toString();
            } catch (Exception ex) {
                result = "Error";
            }

            return result;
        }

In my case, I want to save data to the server, but I can’t save data into the server. Can anyone help me?

  • 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-05-30T22:35:03+00:00Added an answer on May 30, 2026 at 10:35 pm

    see this example.I think it may help to you

             JSONObject json = new JSONObject(); 
             try {
                 HttpClient httpclient = new DefaultHttpClient();
                 HttpPost httppost = new HttpPost("http://www.mernalaw.com/financeassessment.php");
                 json.put("Income","1 - $30,000"); 
                 json.put("Household","1");  
    
                 json.put("Employment","Employed"); 
                 json.put("RealEstate","Primary residence"); 
                 json.put("Vehicle","No"); 
                 json.put("Name","vvk"); 
                 json.put("Email","vvkrishna1989@gmail.com"); 
                 json.put("CellPhone","99999999999"); 
                 json.put("City","hyd"); 
    
                 Log.i("jason Object", json.toString()); 
                 httppost.setHeader("json", json.toString()); 
    
                 StringEntity se = new StringEntity(json.toString());
                 se.setContentEncoding("UTF-8"); 
                 se.setContentType("application/json"); 
                 httppost.setEntity(se);              
                 HttpResponse response = httpclient.execute(httppost); 
                 int statusCode = response.getStatusLine().getStatusCode(); 
                 Toast.makeText(getApplicationContext(),String.valueOf(statusCode), Toast.LENGTH_SHORT).show();
                 is = se.getContent();
                 Log.e("log_tag", "connection success "+"status code"+statusCode);
                 Toast.makeText(getApplicationContext(), "Successfully Connected", Toast.LENGTH_SHORT).show();
                }
                catch(Exception e){
                 Log.e("log_tag", "Error in http connection "+e.toString());
                 Toast.makeText(getApplicationContext(), "Fail to Connect", Toast.LENGTH_SHORT).show();
                }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to save some custom data into application configuration file and I need
How can I save a byte[] array into a SQL Server database? This byte[]
I want to save and load my xml data using XmlReader. But I don't
I want to setup a table that can: Save the data on the user's
i've got some binary data which i want to save as an image. When
I want to provide the ability to save some rendered data/charts (with the titles
I want to save and store simple mail objects via serializing, but I get
I have this code written up to snatch some weather data and make it
I have these Javascript classes/code: function PageManager () { this.digital_channels = undefined; this.loadConfiguration =
I want to save the objects I generated in a program. After restart the

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.