这种情况涉及将字符串数据从一个活动传递到另一个活动。我想使用这个变量(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;
}
}
?>
最终通过妥善处理API方面解决了此问题。感谢所有受访者。
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
if ($_SERVER['REQUEST_METHOD'] == 'POST')
try{
$useremail = $_REQUEST["useremail"];
include 'dbconfig.php';
$conn = new PDO("mysql:host=$HostName;dbname=$DatabaseName", $HostUser, $HostPass);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT * FROM `table1` WHERE `useremail` = '$useremail'");
$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;
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句