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

  • Home
  • SEARCH
  • 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 8439529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:01:21+00:00 2026-06-10T08:01:21+00:00

i am trying to post data through android forms to mysql database. i am

  • 0

i am trying to post data through android forms to mysql database. i am posting data to a PHP script hosted on the server. i am getting null values in MYSQL. the webservice is getting called but it is getting blank data below is my android code code:

package com.register;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;



import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.app.Activity;

public class Register extends Activity {




    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_register);
        EditText email_id = (EditText)  findViewById(R.id.email_id) ;
        EditText name = (EditText) findViewById(R.id.name);
        EditText password = (EditText) findViewById(R.id.password);
        Button button = (Button) findViewById(R.id.button1) ;

        final String email = email_id.getText().toString();
        final String fullname = name.getText().toString();
        final String mpassword = password.getText().toString();



        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();

        StrictMode.setThreadPolicy(policy); 
button.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View arg0) {
        // TODO Auto-generated method stub
        //postData();
          HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost("http://xyz/register.php");

            try {
                // Add your data
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("email", email));
                nameValuePairs.add(new BasicNameValuePair("name", fullname));
                nameValuePairs.add(new BasicNameValuePair("password", mpassword));
               httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = httpclient.execute(httppost);

            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
            } catch (IOException e) {
                // TODO Auto-generated catch block
            }

    }
});

    }

Below is my PHP code :

mysql_connect("server","user","password");
mysql_select_db("testms");
$email =   $_POST['email'];
$name =    $_POST['name'] ;
$password = $_POST['password'] ;

$query_add="INSERT INTO  users (`email` ,`name` ,`password` )
VALUES ('".$email."','".$name."', '".$password."')";
$query_exec=mysql_query($query_add) or die(mysql_error()); 
mysql_close();      

    }
  • 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-10T08:01:22+00:00Added an answer on June 10, 2026 at 8:01 am

    The code below should work, but it is not tested – I just copied over from a project I am working on. I will update the MySQL interaction in the PHP section to mysqli (the CORRECT method) in a couple minutes and I will just edit my answer. For now, just know that using mysql_* is depreciated, and you should really sanitize all entries to and from your database. Anyway, give this a whirl:

    Java:

    @Override
    public void onClick(View arg0) {
        // generate your params:
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("email", email));
        nameValuePairs.add(new BasicNameValuePair("name", fullname));
        nameValuePairs.add(new BasicNameValuePair("password", mpassword));
    
        // send them on their way
        try {
            DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpPost httpPost = new HttpPost("http://xyz/register.php");
            httpPost.setEntity(new UrlEncodedFormEntity(nameValueParams));
    
            HttpResponse httpResponse = httpClient.execute(httpPost);
            HttpEntity httpEntity = httpResponse.getEntity();
    
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    

    PHP (depreciated/unsanitized):

    <?php 
    
        $connection = mysql_connect("hostname", "username", "password")or die(mysql_error());
        $selection = mysql_select_db("database", $connection)or die(mysql_error());
    
        // You should echo these variables back to your app
        // so you know they are sending.
        // echo "Received: " . $email . " - " . $name . " - " . $password;
        $email = $_POST['email'];
        $name = $_POST['name'];
        $password = $_POST['password'];
    
        $insert = "INSERT INTO users('email','name','password') VALUES('$email','$name','$password')";
        $run = mysql_query($insert)or die(mysql_error());
    
    ?>
    

    A Better PHP Example:

    <?php   
        $mysqli_connection = new mysqli("hostname", "username", "password", "database");
        if ($mysqli_connection->connect_errno) {
            echo ("Connection Failure");
            exit();
        }
    
        $email = mysql_real_escape_string($_POST['email']);
        $name = mysql_real_escape_string($_POST['name']);
        $password = mysql_real_escape_string($_POST['password']);
    
        $insert = "INSERT INTO users('email','name','password') VALUES('$email','$name','$password')";
        if ($run = $mysql_connection->query($insert)) {
            echo 'Success';
            $run->free();
            $mysql_connection->close();
        } else {
            echo 'Error Inserting Content';
            exit();
        }
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to post data from PHP to Server which is built in
I'm trying to read POST data in a PHP script. My first instincts led
I am trying to send data through post method in android . But how
I'm trying to post form data in a lightbox through jQuery and php. There
I'm trying to send data through a POST request from a node.js server to
I am trying to send XML data through CURL with HTTP POST in PHP
I am trying to send data from an Android app to a PHP file
i have been trying to call a PHP script with the android system. i
Hi I am trying to post data Using CURL in PHP to diigo bookmarking,
I'm trying to send POST data to a test.php file, which handles POST data

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.