我已經提出了下面的post請求,這似乎工作正常。當我查看網絡中的開發人員工具時,一切似乎都奏效,我可以看到每個參數都已發佈。然而,當insert.php
執行沒有被添加到數據庫,我沒有收到任何錯誤消息。我試圖將圖像保存到MySQL中的Blob中。發佈請求數據沒有被插入到mysql
POST請求
var description = $('#description').val();
var title = $('#title').val();
var fileInput = $("#image")[0];
var file = fileInput.files[0];
var dataResult = new FormData();
dataResult.append('image', file);
dataResult.append('desc', description);
dataResult.append('title', title);
dataResult.append('longitude', currentMarker.lng());
dataResult.append('latitude', currentMarker.lat());
$.ajax({
type: 'POST',
url: 'insert.php',
data: dataResult,
processData: false,
contentType: false,
success: function (answer) {
}
})
insert.php
include('config.php');
if (isset($_POST['title']) && isset($_POST['body']) && isset($_POST['longitude']) && isset($_POST['latitude'])){
$title = $_POST['title'];
$body = $_POST['body'];
$longitude = (float)$_POST['longitude'];
$latitude = (float)$_POST['latitude'];
$file = file_get_contents($_FILES['image']['name']);
$strSQL = $db->query("INSERT INTO camps (title, body, longitude, latitude, image) VALUES ('$title', '$body', '$longitude','$latitude', '$file')");
}
自卸
array(4) {
["desc"]=>
string(6) "teeest"
["title"]=>
string(11) "test"
["longitude"]=>
string(18) "-74.17870044708252"
["latitude"]=>
string(17) "40.73480350827126"
}
也許你可以把你的'$ db-> query'放入一個try catch塊中,並捕獲Exception(如果有的話)。你是否已經檢查了Web服務器錯誤日誌和/或MySQL錯誤日誌?什麼是查詢的原始版本? – codedge
'var_dump''$ _POST'來檢查您收到的內容。如果您使用的是Chrome,則可以使用Postman -rest客戶端進行ajax請求。 – dipesh
在php開始標記之後,在開始處添加'error_reporting(E_ALL);'到您的'insert.php',然後重試並讓我們知道您是否有任何錯誤。 –