我有PHP文件裏面的wamp服務器。當我在localhost中運行該文件時,會出現如下所示的錯誤。php文件沒有顯示錯誤
這是我的PHP文件:
<?php
$response = array({
"success": [
{
"message": "Required field id missing"
},
{
"message": "successfully created."
},
{
"message": "Oops! An error occured"
}
]}
);
if (isset($_POST['name']) && isset($_POST['price']) && isset($_POST['description'])) {
$name = $_POST['name'];
$price = $_POST['price'];
$description = $_POST['description'];
require_once __DIR__ . '/db_connect.php';
$db = new DB_CONNECT();
$result = mysql_query("INSERT INTO products(name, price, description) VALUES('$name', '$price', '$description')");
if ($result) {
$response["success"] = 1;
$response["message"] = "Product successfully created.";
echo json_encode($response);
} else {
$response["success"] = 2;
$response["message"] = "Oops! An error occurred.";
echo json_encode($response);
}
} else {
$response["success"] = 0;
$response["message"] = "Required field(s) is missing";
echo json_encode($response);
}
?>
,當我在本地主機上運行它下面的錯誤顯示,
(!) Parse error: syntax error, unexpected '{', expecting ')' in D:\wamp\www\android\create_product.php on line 2
還建議我,如何將localPath在瀏覽器中運行PHP文件。
我猜你是混入PHP和JS ..! –
是的。使用該問題的任何問題? – user2928135
您的查詢存在SQL注入風險。順便說一句,你不需要在頂部的 – nik