我需要插入到数据库中,但是它给了我错误,我刚看到silimar示例,但我的工作不正常请告诉我是什么问题:
<?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,它必须显示{&#34;成功&#34;:1,&#34;消息&#34;:true},但它确实如此请不要帮助我
答案 0 :(得分:1)
试试这个
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_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]')");
你有'$ _ POST [P_Price]',重复两次。
答案 1 :(得分:0)
如果这与您的其他问题有关:PHP does not insert into mysql
三个问题:
我已更正此 DEMO (已删除的外键关联)中的问题
尝试以下INSERT:
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_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])");
答案 2 :(得分:0)
您必须注意sql语句中的名称,列数和名称以及相应值的数量。