0

我遇到了问题...当用户注册时,我试图将设备的 udid 存储到我的数据库中...我在 logcat 中收到此错误:

10-18 17:17:08.141: E/JSON(1712): <br />
10-18 17:17:08.141: E/JSON(1712): <b>Warning</b>:  Missing argument 4 for DB_Functions::storeUser(), called in /home/matbest1/public_html/android_login_api/index.php on line 64 and defined in <b>/home/matbest1/public_html/android_login_api/include/DB_Functions.php</b> on line <b>25</b><br />
10-18 17:17:08.141: E/JSON(1712): {"tag":"register","success":0,"error":1,"error_msg":"Error occured in Registartion"}
10-18 17:17:08.151: E/JSON Parser(1712): Error parsing data org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
10-18 17:17:08.381: D/dalvikvm(1712): GC_CONCURRENT freed 296K, 5% free 9394K/9799K, paused 2ms+4ms

我正在尝试将 udid 存储在数据库中......继承人的注册活动:

public JSONObject registerUser(String name, String email, String password, String uid){
    // Building Parameters
    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("tag", register_tag));
    params.add(new BasicNameValuePair("name", name));
    params.add(new BasicNameValuePair("email", email));
    params.add(new BasicNameValuePair("password", password));
    params.add(new BasicNameValuePair("uid", uid));

    // getting JSON Object
    JSONObject json = jsonParser.getJSONFromUrl(registerURL, params);
    // return json
    return json;
}

登记:

UserFunctions userFunction = new UserFunctions();
            JSONObject json = userFunction.registerUser(name, email, password, uid);

php代码:

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

&

  if ($tag == 'register') {
        // Request type is Register new user
        $name = $_POST['name'];
        $email = $_POST['email'];
        $password = $_POST['password'];
        $uid = $_POST['uid'];

        // 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, $email, $password);
            if ($user) {
                // user stored successfully
                $response["success"] = 1;
                $response["uid"] = $user["unique_id"];
                $response["user"]["name"] = $user["name"];
                $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";
}

有人能帮我吗?我是新手...非常感谢。

4

1 回答 1

1

服务器响应包含一个以 HTML 显示的 PHP 错误。

因此,您的 android 应用程序无法解析任何 JSON 是正常的。

首先,您需要确保您的 android 应用程序发送了所有需要的信息(PHP 等待的 4 个参数),因为 PHP 错误清除告诉您它缺少参数 #4:$uid

在您的 php 文件的开头尝试 a print_r($_REQUEST); 以查看 PHP 是否接收所有参数。如果没有:问题出在您的 android 应用程序中(uid 是字符串?整数?你需要转换它吗?)

于 2012-10-18T19:16:44.507 回答