我有這段代碼從一個url傳遞一個變量。當我使用$ _GET方法時,它會返回一個沒有找到產品的json,但是當我手動給出$ user_email從url返回的值時,它會返回正確的json!什麼是錯的,我該如何糾正它?謝謝php文件錯誤中的SQL查詢
網址: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);
}
?>
var_dump($ _ GET ['user_email'])'output'是什麼? – ponysmith
並且您沒有任何機會發布到此方法? – nickL
string(1)「m」這是var_dump的輸出($ _GET ['user_email']) – appLogic