[ASK] 我的php錯誤「失敗的查詢您的SQL語法中有錯誤;請查看與您的MariaDB服務器版本對應的手冊,以獲取正確的語法(iduser,idfood,jumlah,total)VALUES(9,1,2,20000)'在第1行「 什麼是錯誤....?失敗的查詢您在SQL語法中遇到錯誤
myphp
<?php
$data= file_get_contents('php://input');
$array = json_decode($data, true);
require_once ('..../db_connectfood.php');
$db = new DB_CONNECT();
foreach($array as $row)
{
$idusr = $row["iduser"];
$idfd = $row["idfood"];
$jml = $row["jumlah"];
$total = $row["total"];
$result = mysql_query("INSERT INTO order (iduser, idfood, jumlah, total) VALUES ($idusr, $idfd, $jml, $total)") or die ("Failed query ".mysql_error());
}
if ($result) {
// successfully inserted into database
$response["success"] = 1;
$response["message"] = "successfully created.";
// echoing JSON response
echo json_encode($response);
} else {
// failed to insert row
$response["success"] = 0;
$response["message"] = "Oops! An error occurred.";
// echoing JSON response
echo json_encode($response);
}
?>
如何得到這個PHP的成功價值和消息?
ID用戶和idfood是外鍵
您的表是否有名爲「iduser」的列?如果你從一個MySQL管理器執行該查詢,它是否工作? – Jason