我有这段代码从 url 传递一个变量。当我使用 $_GET 方法时,它会返回一个未找到产品的 json,但是当我手动给出 $user_email 从 url 获得的值时,它会返回正确的 json!出了什么问题,我该如何纠正?谢谢你
网址:http:// * ** * ** * ** * * /android_connect/get_all_products.php?user_email=m
<?php
/*
* Following code will list all the products
*/
// array for JSON response
$response = array();
$user_email= $_GET['user_email'];
// include db connect class
require_once __DIR__ . '/db_connect.php';
// connecting to db
$db = new DB_CONNECT();
// get all products from products table
$test= "SELECT *FROM products WHERE user_email= '" .$user_email. "'";
//echo $test;
$result = mysql_query($test) or die(mysql_error());
// check for empty result
if (mysql_num_rows($result) > 0) {
// looping through all results
// products node
$response["products"] = array();
while ($row = mysql_fetch_array($result)) {
// temp user array
$product = array();
$product["pid"] = $row["pid"];
$product["firstname"] = $row["firstname"];
$product["lastname"] = $row["lastname"];
$product["email"] = $row["email"];
$product["phone"] = $row["phone"];
$product["address"] = $row["address"];
$product["created_at"] = $row["created_at"];
$product["updated_at"] = $row["updated_at"];
$product["user_email"] = $row["user_email"];
// push single product into final response array
array_push($response["products"], $product);
}
// success
$response["success"] = 1;
// echoing JSON response
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
// echo no users JSON
echo json_encode($response);
}
?>