0

Android アプリケーションが受信した入力を myphpadmin サーバーに送信するのに苦労しています。

私のアプリケーションがphpスクリプトを実行してサーバーに情報を送信できるようにするには、Andriodコーディングに何を追加する必要があるのか​​ 疑問に思っています。

これまでに行ったことは、構成と接続の目的で php スクリプトを作成することです。

<?php
define('DB_USER', "root"); // db user
define('DB_PASSWORD', "password"); // db password (mention your db password here)
define('DB_DATABASE', "Wifi"); // database name
define('DB_SERVER', "http://andy-009.dlink.net/"); // db server
?>

/**
 * A class file to connect to database
 */
class DB_CONNECT {

    // constructor
    function __construct() {
        // connecting to database
        $this->connect();}
    // destructor
    function __destruct() {
        // closing db connection
        $this->close();}
  /**
     * Function to connect with database
     */
    function connect() {
        // import database connection variables
        require_once __DIR__ . '/db_config.php';

        // Connecting to mysql database
        $con = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD) or die(mysql_error());

        // Selecing database
        $db = mysql_select_db(DB_DATABASE) or die(mysql_error()) or die(mysql_error());

        // returing connection cursor
        return $con; }
    /**
     * Function to close db connection
     */
    function close() {
        // closing db connection
        mysql_close();
    } }

挿入phpスクリプトと同様に

update_product.php
<?php

/*
 * Following code will update a product information
 * A product is identified by product id (pid)
 */

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

// check for required fields
if (isset($_POST['WifiMacAddress']) && isset($_POST['WifiSSID']) && isset($_POST['WifiLatitude']) && isset($_POST['WifiLongtitude']) && isset($_POST['WifiLocation'])) {

    $WifiMacAddress = $_POST['WifiMacAddress'];
    $WifiSSID = $_POST['WifiSSID'];
    $WifiLatitude = $_POST['WifiLatitude'];
    $WifiLongtitude = $_POST['WifiLongtitude'];
    $WifiLocation = $_POST['WifiLocation'];

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

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

    // mysql update row with matched pid
    $result = mysql_query("UPDATE Wifi SET WifiSSID = '$WifiSSID', WifiLatitude = '$WifiLatitude', WifiLongtitude = '$WifiLongtitude' , WifiLocation = '$WifiLocation' WHERE WifiMacAddress = $WifiMacAddress");

    // check if row inserted or not
    if ($result) {
        // successfully updated
        $response["success"] = 1;
        $response["message"] = "Product successfully updated.";

        // echoing JSON response
        echo json_encode($response);
    } else {

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

    // echoing JSON response
    echo json_encode($response);
}
?>
4

1 に答える 1

0

Android と php の間の通信には、JSON が役立つと思います。

両端でデータを JSON に解析し、Web サービスを使用してインターネット経由で送信できます。

于 2013-08-23T08:58:04.327 に答える