0
我的sql不允許我插入數據。它曾經工作,但我想我意外地改變了下面的代碼中的東西。返回的錯誤是:「錯誤:您的SQL語法出錯;檢查與您的MySQL服務器版本相對應的手冊,以在'home','111-333-111','2 ' '2第2" 行 這裏', '1')' 是PHP/SQL代碼:我的SQL INSERT不能在PHP中工作
$house = $_GET['houseid'];
//connect to DB
$servername = "localhost";
$dusername = "root";
$dpassword = "Think";
$dbname= "realstate";
$id = $_SESSION['userid'];
//define home property variables
$data_province = $_POST["province"];
$data_country = $_POST["country"];
$data_city = $_POST["city"];
$data_type = $_POST["proptype"];
$data_bedroom = $_POST["bedroomnumb"];
$data_bathroom = $_POST["bathnumb"];
$data_community = $_POST["community"];
$data_price1 = $_POST["price1"];
$data_price2 = $_POST["price2"];
$data_price3 = $_POST["price3"];
$data_price = $data_price1 . "-" . $data_price2 . "-" . $data_price3;
$data_street = $_POST["street"];
$data_number = $_POST["number"];
if (isset ($_POST["furnished"])){
$data_furnished = 1;
} else {
$data_furnished = 0;
}
if (empty($data_province) || empty($data_country) || empty($data_city) || empty($data_type) || empty($data_bedroom) || empty($data_bathroom) || empty($data_community) || empty($data_price) ||
empty($data_street) || empty ($data_number)){
header('Location: /~ideen/sites/realestate/createproperty.php?errorfillall');
}
// Create connection
$conn = new mysqli($realstate, $dusername, $dpassword, $dbname);
$insertdata = "INSERT INTO Porperties (Country, Province, City, Community, Street, Number, Type, Price, Bathnumb, Bednumb, Furnished)
VALUES('$data_country', '$data_province', '$data_city', '$data_community', '$data_street', '$data_number, '$data_type', '$data_price', '$data_bathroom', '$data_bedroom', '$data_furnished')";
if ($conn->query($insertdata) === TRUE) {
$last_id = $conn->insert_id;
$filenumero = $last_id;
echo "SQL succes";
缺少引號,我會讓你找到我t – 2016-01-23 20:08:49
在$'data_number'上缺少一個報價。而且,這段代碼對於SQL注入是可行的,最好使用mysqli或PDO。最後但並非最不重要的一點是,除非你想繼續下面的代碼,否則當使用'header()'後面跟着'exit()'或'die()'。 – Xorifelse