Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何发送从其他活动发送的数据?_Php_Android_Mysql_Eclipse_Listview - Fatal编程技术网

Php 如何发送从其他活动发送的数据?

Php 如何发送从其他活动发送的数据?,php,android,mysql,eclipse,listview,Php,Android,Mysql,Eclipse,Listview,在列出项目之前,我有一个应用程序的功能来创建一个新的数据,其中包含来自另一个活动的唯一id。唯一的数据是“sid”。我使用PHP连接到一个phpmyadmin数据库 <?php // array for JSON response $response = array(); // check for required fields if (isset($_POST['foodName']) && isset($_POST['foodPrice']) &&

在列出项目之前,我有一个应用程序的功能来创建一个新的数据,其中包含来自另一个活动的唯一id。唯一的数据是“sid”。我使用PHP连接到一个phpmyadmin数据库

<?php

// array for JSON response
$response = array();

// check for required fields
if (isset($_POST['foodName']) && isset($_POST['foodPrice']) && isset($_POST['foodType']) && isset($_POST['sid']) {

$foodName = $_POST['foodName'];
$foodPrice = $_POST['foodPrice'];
$foodType = $_POST['foodType'];
$sid = $_POST['sid'];

// include db connect class
require_once __DIR__ . '/db_connect.php';

// connecting to db
$db = new DB_CONNECT();

// mysql inserting a new row
$result = mysql_query("INSERT INTO food(foodName, foodPrice, foodType, sid) VALUES('$foodName', '$foodPrice', '$foodType', '$sid')");

// check if row inserted or not
if ($result) {
    // successfully inserted into database
    $response["success"] = 1;
    $response["message"] = "Food successfully created.";

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

    // echoing JSON response
    echo json_encode($response);
}
} else {
// required field is missing
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";

// echoing JSON response
echo json_encode($response);
}
?>
最后,在执行时,我在类中有如下命令:

protected String doInBackground(String... args) {

        // Building Parameters
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("foodName", getFoodName));
        params.add(new BasicNameValuePair("foodPrice", getFoodPrice));
        params.add(new BasicNameValuePair("foodType", getFoodType));
        params.add(new BasicNameValuePair("sid", sid));
受保护的字符串doInBackground(字符串…args){
//建筑参数
List params=new ArrayList();
添加(新的BasicNameValuePair(“foodName”,getFoodName));
参数add(新的BasicNameValuePair(“foodPrice”,getFoodPrice));
添加(新的BasicNameValuePair(“foodType”,getFoodType));
添加(新的BasicNameValuePair(“sid”,sid));

有什么地方我做错了吗?在我的桌子上我也有这个“sid”。

你必须做以下事情 在第一个活动中

Intent intent = new Intent(getBaseContext(), SignoutActivity.class);
intent.putExtra("sid", VALUE);
startActivity(intent);
在第二个活动中

Bundle extras = getIntent().getExtras();
if (extras != null) {
    String value = extras.getString("sid");
}

如果您知道要将字符串作为额外值获取,则可以直接使用
String extra=getIntent().getExtraString(“sid”);
If条件仅为额外检查,有时您需要调用活动而不添加任何具有此意图的数据。
Bundle extras = getIntent().getExtras();
if (extras != null) {
    String value = extras.getString("sid");
}