[Android改造基于用户输入的数据获取

问题描述 投票:0回答:1

这种情况涉及将字符串数据从一个活动传递到另一个活动。我想使用这个变量(useremail)来选择MySQL数据库中的数据。数据未从服务器返回任何内容。我正在尝试使用翻新来做到这一点。我在哪里可能出问题了?。

API接口

public interface ApiInterface2 {
    String BASE_URL = "10.0.2.2/uploadmultiple/";
    @POST("mylist.php")
    Call<List<ImageList>> getImgData(@Query("useremail") String userEmail);}

主要类别

  Call<List<ImageList>> call = apiInterface.getImgData(userEmail);
        call.enqueue(new Callback<List<ImageList>>() {
            @Override
            public void onResponse(Call<List<ImageList>> call, Response<List<ImageList>> response) {
                if (response.isSuccessful()) {
                    if (response.body() != null) {

                        imageLists = response.body();
                        adapter = new ListingsAdapter(imageLists, MyListings.this);
           ////////
 });
<?php

include 'dbconfig.php';

if ($_SERVER['REQUEST_METHOD'] == 'POST') { 

    $useremail = $_POST["useremail"];

    if(empty($useremail)){echo "UserEmail is null";}

try {

    $email = $_REQUEST["useremail"];
    // Create connection
    $conn = new PDO("mysql:host=$HostName;dbname=$DatabaseName", $HostUser, $HostPass);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


    $stmt = $conn->prepare("SELECT * FROM `tabe1` WHERE `useremail` = $email"); 

    $stmt->execute();

    $data=array();
    while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
        $data[] = $row; 
    }
    header('Content-Type:Application/json');
    echo json_encode($data);
    }
    catch (PDOException $e) {
    print "Connection failed! Please Try Again Or Contact Us: " . $e->getMessage() . "<br/>";
    die();
    $conn = null;
    }
    }

?>
java android mysql retrofit
1个回答
0
投票

我认为应该是这样,BASE_URL应该仅在retrofit中包含URL,而不是路径。

String BASE_URL = "10.0.2.2/";
@POST("uploadmultiple /mylist.php")

这应该对您有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.