我需要插入数据库,但它给了我错误,我只是在这里看到了类似的例子,但我的不工作请告诉我问题是什么:
<?php
$con = mysql_connect("localhost","****","****");
if (!$con)
{
die('Could not connect: '. mysql_error());
}
mysql_select_db("properties", $con);
// array for JSON response
$response = array();
$result = mysql_query("INSERT INTO property( Pname, P_Price,P_Desc,P_City, P_Size,P_Rooms, P_garage, P_Address, P_Long, P_Lat, Provinces_idProvinces)
VALUES
('$_POST[Pname]','$_POST[P_Price]','$_POST[P_Price]','$_POST[P_Desc]','$_POST[P_City]','$_POST[P_Size]','$_POST[P_Rooms]','$_POST[P_garage]','$_POST[P_Address]','$_POST[P_Long]','$_POST[P_Lat]','$_POST[Provinces_idProvinces]')");
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = $result ;
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";
echo $response["success"];
// echoing JSON response
echo json_encode($response);
}
mysql_close();
?>
我需要这样的网址:localhost/php/add.php,它必须显示 {"success":1,"message":true} ,但它不请帮助我