php无法存储数据,无法在变量中使用$ _POST()在PHP端存储值,但可以轻松地将其存储在数据库中...

I am accepting values from android to php. My android code successfully sends data to php server, but my php code is unable to store the value of $_POST() variable in another variable.But when i directly put the $_POST() in insert query, the the value gets stored in the database.When i try var_dump($_POST()) it shows null.

Can you pls help me , on how to get the $_POST() value in another variable.

Android Code

//send.java

package com.exg.zzz;

import java.io.IOException;

import java.util.ArrayList;

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.app.Activity;

import android.os.Bundle;

import android.util.Log;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

public class send extends Activity {

EditText edit_uid,edit_pwd;

Button btn_login;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

edit_uid=(EditText) findViewById(R.id.edit_uid);

edit_pwd=(EditText) findViewById(R.id.edit_pwd);

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

btn_login.setOnClickListener(new OnClickListener(){

@Override

public void onClick(View v){

http_connection();

}

});

}

void http_connection()

{

ArrayList nameValuePairs = new ArrayList(2);

nameValuePairs.add(new BasicNameValuePair("Password",edit_pwd.getText().toString()));

nameValuePairs.add(new BasicNameValuePair("UID",edit_uid.getText().toString()));

HttpClient httpclient1 = new DefaultHttpClient();

HttpPost httppost1 = new HttpPost("http://10.0.2.2/userins1.php");

Log.v("localhost", "executed");

try {

httppost1.setEntity(new UrlEncodedFormEntity(nameValuePairs));

httpclient1.execute(httppost1);

} catch (ClientProtocolException e) {

// TODO Auto-generated catch block

e.printStackTrace();

} catch (IOException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

Toast.makeText(this, "Added", Toast.LENGTH_SHORT).show();

}

}PHP code

//userins1.php

$username = "root";

$password = "";

$hostname = "localhost";

//var_dump() display the data type and contents of the variable

//but it displaying NULL for string data

var_dump($_POST[UID]);

//connection to the database

$dbhandle = mysql_connect($hostname, $username, $password)

or die("Unable to connect to MySQL");

//select a database to work with

$selected = mysql_select_db("akshay",$dbhandle)

or die("Could not select examples");

//execute the SQL query and return records

//this qyery is successfully inserting the data

$sql="INSERT INTO login (uid, password) VALUES ('$_POST[UID]','$_POST[Password]')";

if (!mysql_query($sql,$dbhandle))

{

die('Error: ' . mysql_error());

}

mysql_close($dbhandle);

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值