[ASK] my php error "失敗したクエリSQL構文にエラーがあります。使用する正しい構文については、MariaDBサーバのバージョンに対応するマニュアルをチェックしてください(iduser、idfood、jumlah、total)VALUES(9,1,2,20000) 'at line 1 " 何が間違っていますか?このPHPから値の成功とメッセージを取得する方法を失敗したクエリ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);
}
?>
?
iduserとidfoodこんにちは、外部キー
テーブルに「iduser」という名前の列がありますか? mysqlマネージャーからそのクエリを実行すると動作しますか? – Jason