我正在尝试创建一个订单表单,餐厅的人员可以手动从客户那里接受订单。 然后看他们做了什么订单。
我的语句一直拒绝将这些数据插入数据库。 我想知道我在这里做错了。,
这是我的数据库:
MenuItem:
MenuItemID int(11)
ItemName varchar(255)
ItemPrice double
orders:
OrderID int(11)
MenuItemID int(11)
ReceiptID int(11)
Res_Datum date
Tafel_Id int(11)
Res_ID int(11)
receipt:
ReceiptID int(11)
ReceiptPrice double
reserveringen:
Reservering_Id int(11)
Tafel_Id int(11)
VoorNaam varchar(255)
AchterNaam varchar(255)
TelefoonNummer varchar(255)
Email varchar(255)
Res_Datum date
tafels:
Tafel_Id int(11)
tafel_Nummer int(11)
Aantal_Personen int(11)
按订单显示订单。Tafel_Id,orders.ReceiptID,orders.MenuItemID,orders.ReceiptID,orders.Res_Datum
$sql = "SELECT O.Res_Datum, O.Res_ID, O.Tafel_Id,O.ReceiptID, SUM(MI.ItemPrice) AS TotalReceiptPrice
FROM Orders AS O INNER JOIN MenuItem AS MI ON O.MenuItemID = MI.MenuItemID
GROUP BY O.Res_Datum, O.Res_ID, O.Tafel_Id ";
$result = $conn->query($sql);
我正在尝试通过此表单将这些数据插入数据库中,但是我无法弄清为什么它不起作用。
Maak_bestelling.php:
<?php
$con = mysqli_connect('localhost','root','');
if(!$con) {
echo 'Not connected with server';
}
if(!mysqli_select_db ($con,'restaurant')) {
echo 'Database Not selected';
}
$tablenumber = $_POST['tafelnummer'];
$receiptid = $_POST['receiptid'];
$menu_item = $_POST['menu_item'];
$date = $_POST['date'];
$sql = "INSERT INTO Orders (orders.Tafel_Id, orders.ReceiptID, orders.MenuItemID, orders.ReceiptID, orders.Res_Datum )
VALUES ('$tablenumber', '$receiptid', '$menu_item', '$date')";
if(!mysqli_query($con,$sql)){
echo 'insert did not work';
}else {
echo 'Order created successfully';
}
header("refresh:1; url=bestelling.php");
bestelling.php:
<form action="/restaurant/maak_bestelling.php" method="POST">
<h2>Enter Order</h2>
Table Number:<br>
<input type="text" name="tafelnummer" value=""><br><br>
Receipt Id:<br>
<input type="text" name="receiptid" value=""><br><br>
Menu_Item:<br>
<input type="text" name="menu_item" value=""><br><br>
Date: <br>
<input type="date" name="date" value=""><br><br>
<input type="submit" value="Submit">
</form>
<h2>Pending Orders:</h2>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "restaurant";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
//$sql = "SELECT O.Res_Datum,O.Res_ID, O.Tafel_Id, SUM(MI.ItemPrice) AS TotalReceiptPrice FROM Orders AS O INNER JOIN MenuItem AS MI ON O.MenuItemID = MI.MenuItemID ";
$sql = "SELECT O.Res_Datum, O.Res_ID, O.Tafel_Id,O.ReceiptID, SUM(MI.ItemPrice) AS TotalReceiptPrice
FROM Orders AS O INNER JOIN MenuItem AS MI ON O.MenuItemID = MI.MenuItemID
GROUP BY O.Res_Datum, O.Res_ID, O.Tafel_Id ";
$result = $conn->query($sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo "Res_datum: ". $row["Res_Datum"]. " ReservationID : " . $row["Res_ID"]. " - Table_Number: " . $row["Tafel_Id"]. " Total Order Price: " . $row["TotalReceiptPrice"]." ". "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>
</div>
答案 0 :(得分:0)
在插入语句中,您重复了ReceipID,因此必须像这样删除它:
$sql = "INSERT INTO Orders (orders.Tafel_Id, orders.ReceiptID, orders.MenuItemID, orders.Res_Datum )
VALUES ('$tablenumber', '$receiptid', '$menu_item', '$date')";