0

DBテーブルをローカルサーバーのPHPフォーラムと共有するAndroidアプリをコーディングしています。私のアプリ ユーザーは、アプリの使用を開始する前に登録する必要があります。私のアプリの機能の 1 つは、これらの登録済みユーザーが投稿やコメントをフォーラムに送信/表示できるようにすることです。フォーラム全体を自分の電話に呼び出すことで、このタスクではさまざまな応答で JSON を使用しました。残念ながら、登録するたびにエラー応答が返されますが、その理由がわかりませんでした

これは私が得たエラー応答です

03-14 16:14:52.361: E/JSON(400): {"tag":"register","success":0,"error":1,"error_msg":"Error occured in Registartion"}

これは私のindex.phpです

<?php

   /**
 * File to handle all API requests
 * Accepts GET and POST
*
* Each request will be identified by TAG
 * Response will be JSON data

/**
* check for POST request
 */
if (isset($_POST['tag']) && $_POST['tag'] != '') {
// get tag
$tag = $_POST['tag'];

// include db handler
require_once 'include/DB_Functions.php';
$db = new DB_Functions();

// response Array
$response = array("tag" => $tag, "success" => 0, "error" => 0);

// check for tag type
if ($tag == 'login') {
    // Request type is check Login
    $email = $_POST['email'];
    $password = $_POST['password'];

    // check for user
    $user = $db->getUserByEmailAndPassword($email, $password);
    if ($user != false) {
        // user found
        // echo json with success = 1
        $response["success"] = 1;
        $response["id"] = $user["unique_id"];
        $response["user"]["name"] = $user["username"];
        $response["user"]["email"] = $user["email"];
        $response["user"]["created_at"] = $user["created_at"];
        $response["user"]["updated_at"] = $user["updated_at"];
        echo json_encode($response);
    } else {
        // user not found
        // echo json with error = 1
        $response["error"] = 1;
        $response["error_msg"] = "Incorrect email or password!";
        echo json_encode($response);
    }
} else if ($tag == 'register') {
    // Request type is Register new user
    $name = $_POST['username'];
    $email = $_POST['email'];
    $password = $_POST['password'];

    // check if user is already existed
    if ($db->isUserExisted($email)) {
        // user is already existed - error response
        $response["error"] = 2;
        $response["error_msg"] = "User already existed";
        echo json_encode($response);
    } else {
        // store user
        $user = $db->storeUser($name,  $password, $email);
        if ($user) {
            // user stored successfully
            $response["success"] = 1;
            $response["id"] = $user["unique_id"];
            $response["user"]["name"] = $user["username"];
            $response["user"]["email"] = $user["email"];
            $response["user"]["created_at"] = $user["created_at"];
            $response["user"]["updated_at"] = $user["updated_at"];
            echo json_encode($response);
        } else {
            // user failed to store
            $response["error"] = 1;
            $response["error_msg"] = "Error occured in Registartion";
            echo json_encode($response);
        }
    }
} else {
    echo "Invalid Request";
}
  } else {
echo "Access Denied";
  }
  ?>

これは私のSTOREUSERFUNCTIONです

 public function storeUser($name, $password, $email) {
    $uuid = uniqid('', true);
    $hash = $this->hashSSHA($password);
    $encrypted_password = $hash["encrypted"]; // encrypted password
    $salt = $hash["salt"]; // salt
    $result = mysql_query("INSERT INTO user(unique_id, username, password, salt, email,  created_at) VALUES('$uuid', '$name',  '$encrypted_password', '$salt', '$email',  NOW())");
    // check for successful store
    if ($result) {
        // get user details
        $id = mysql_insert_id(); // last inserted id
        $result = mysql_query("SELECT * FROM user WHERE id = $id");
        // return user details
        return mysql_fetch_array($result);
    } else {
        return false;
    }
}

以前は問題なく実行できたので、ここで何が問題なのか本当にわかりませんでしたが、今はこのコードを変更してフォーラムのユーザーテーブルに詳細を保存し、ユーザーデータの1つのテーブルを処理できるようにしました。新しいコードはここにあります-つまり、それはエラー応答の原因ではないと思います-しかし、表には疑問がありますが、エラー応答をトリガーする間違いがどこにあるのかわかりません

4

1 に答える 1

0

さて、ログイン要求を行う Android 側の関数で問題はありませんでした。php ファイルの関数の順序と一致するようにパラメーターが設定されていません。どうもありがとう カルマファンクに感謝します あなたは私をたくさん助けてくれました

私の質問が同じ問題を抱えている他の人に役立つことを願っています。

于 2013-03-16T09:43:40.963 に答える