• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Help Sending variable from android studio to php (xampp server)

Hello guys, I want to send my android studio "name" textbox string in PHP via apache server. I tried the following code, but I didn't get the result. (I have configured internet permission in manifest file by the way)

Android Code: ( I have configured internet permission in manifest file)

btn2.setOnClickListener(new View.OnClickListener() {

InputStream is=null;
@override
public void onClick(View v) {//fired when insert button is clicked

StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
//storing values of edit texts inside string
String getName = naMe.getText().toString();
String getEmail = eMail.getText().toString();
String string1 = getName;
String string2 = getEmail;

//setting the nameValue pairs

List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();

//Adding the string variable inside namevalue pair
nameValuePairs.add(new BasicNameValuePair("Name", string1));
nameValuePairs.add(new BasicNameValuePair("Email", string2));

StrictMode.setThreadPolicy(policy);

//Setting up the connection inside try-cry block
try {
//Setting up the default HttpClient
HttpClient httpClient = new DefaultHttpClient();

//Setting up the http post method
HttpPost httppost = new HttpPost("http://192.168.0.106/niraj/insert.php");

//Passing the name value pairs inside the http post
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
//Getting the response
HttpResponse response = httpClient.execute(httppost);

//setting up the entity
HttpEntity entity=response.getEntity();

//setting up the content inside an input stream reader
is=entity.getContent();
//Displaying the toast message if data is entered
Toast.makeText(getApplicationContext(),"Data Entered Successfully",Toast.LENGTH_LONG).show();




} catch (ClientProtocolException e) {
Log.e("log_tag", "ClientProtocolException");
e.printStackTrace();
} catch (IOException e) {
Log.e("log_tag", "IOException");
e.printStackTrace();
}



}
});

PHP Code:

<?php

$json = $_POST['Name'];
echo $json;

?>

I could get result stating: "Undefined index: Name in C:\xamppp\htdocs\Niraj\insert.php on line 3"

What is the problem?
 
Back
Top Bottom