【发布时间】:2014-04-11 13:16:52
【问题描述】:
谁能帮我解决这个问题,这个php 代码有什么问题?
根据“http://phpcodechecker.com/”:
Parse error: syntax error, unexpected '$response' (T_VARIABLE) in your code on line 7
$response["products"] = array();
get_all_products.php
<?php
$response = array();
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
$result = mysql_query("SELECT *FROM products") or die(mysql_error());
if (mysql_num_rows($result) > 0) {
$response["products"] = array();
while ($row = mysql_fetch_array($result)){
$product = array();
$product["pid"] = $row["pid"];
$product["name"] = $row["name"];
$product["price"] = $row["price"];
$product["created_at"] = $row["created_at"];
$product["updated_at"] = $row["updated_at"];
array_push($response["products"], $product);
}
// success
$response["success"] = 1;
echo json_encode($response);
} else {
// no products found
$response["success"] = 0;
$response["message"] = "No products found";
echo json_encode($response);
}
?>
【问题讨论】:
-
你试过运行代码吗?你得到那个错误了吗?
-
当我通过 phpcodechecker 运行您的代码时,我没有返回任何错误。您是否尝试过在系统上部署代码?此外,使用 mysqli_* 或 PDO 将是理想的,因为 mysql 库已被弃用并且容易受到攻击。
-
代码运行正常,phpcodechecker没有报错
标签: php mysql json parse-error