你能幫我解決這個問題嗎?即時嘗試插入數據到我的數據庫,而不是插入die()輸出;出現無法執行插入查詢?
<?php
if (isset($_GET['submit'])) {
$item_code = mysqli_real_escape_string($conn, $_GET['item_code']);
$item_name = mysqli_real_escape_string($conn, $_GET['item_name']);
$supplier = mysqli_real_escape_string($conn, $_GET['supplier_name']);
$brand = mysqli_real_escape_string($conn, $_GET['brand_name']);
$quantity = mysqli_real_escape_string($conn, $_GET['quantity']);
$unit = mysqli_real_escape_string($conn, $_GET['unit_name']);
$price = mysqli_real_escape_string($conn, $_GET['price']);
$item_type = mysqli_real_escape_string($conn, $_GET['type_name']);
$category = mysqli_real_escape_string($conn, $_GET['cat_name']);
if ($item_code == '' || $item_name == '' || $supplier == '' || $brand == '' ||
$quantity == '' ||
$unit == '' ||
$price == '' ||
$item_type == '' ||
$category == ''
) {
header("Location: item.php?attempt=empty");
} else {
$sql = mysqli_query($conn, "INSERT INTO itemlist (item_name,supplier_name,brand_name,quantity,unit_name,price,type_name,cat_name) values('$item_name','$supplier','$brand','$quantity','$unit','$price','$item_type','$category')")
or die("Could not execute the insert query.");
header("Location: item.php?attempt=saved");
}
}
?>
檢查錯誤'die(「Error description:」。mysqli_error($ conn));' –
將mysqli_error($ conn)'和任何對數據庫的調用一起使用以處理任何錯誤將會很好。請嘗試讓我們知道什麼是確切的錯誤。 – mitkosoft
在sql查詢中加上「''field \''」 –