-2
我有这个html表单,其中有一个可以输入您想要订购的数量的刮刀细节表。在填写完细节并提交之后,顾客细节,工作人员将被插入到表格顺序中,并创建一个auto_increment或者indederid。 Theres另一个表称为orderid和spatulaid作为外键的订单列表,它也有数量。我将如何写入PHP来获得刮刀ID,订单ID和数量插入到我的订单列表中?我需要填写关于刮刀ID和订单ID的特定数量。如何从html获得输入并发送到php并将其插入到表中
<html>
<head><title>Orders</title></head>
<body>
<h1> Order </h1>
<form method='post' action ="insert.php" >
<p>
Customer Details <br>
<textarea rows="4" cols="50" name="customerdetails">
</textarea>
</p>
<p>
Responsible Staff Member:
<input type="text" name="staff">
</p>
<table border="1">
<tr>
<th> Spatula ID </th>
<th> Name </th>
<th> Type </th>
<th> Size </th>
<th> Colour </th>
<th> Price </th>
<th> Quantity currently in stock </th>
<th> Order Quantity </th>
</tr>
<?php
$con = mysqli_connect("localhost","blah","blah","blah");
// Check connection
if (mysqli_connect_errno()) {
echo "Could not connect to MySQL for the following reason: " . mysqli_connect_error();
}
$sql = "Select * FROM Spatula";
$result = mysqli_query($con,$sql);
while($row=mysqli_fetch_array($result)){
echo "<tr><td>".$row['idSpatula']."</td><td>".$row['ProductName']."</td> <td>".
$row['`Type`']."</td><td>".$row['Size']."</td><td>".$row['Colour'].
"</td><td>".$row['Price']."</td><td>".$row['QuantityInStock']."</td><td>"
.'<input type="text" name="quantity"</td></tr>';
}
mysqli_close($con);
?>
</table>
</p>
<input type='submit' value='Submit' />
</form>
</body>
</html>
这是我insert.php
<?php
$con = mysqli_connect("localhost","blah","blah","blah");
// Check connection
if (mysqli_connect_errno()) {
echo "Could not connect to MySQL for the following reason: " . mysqli_connect_error();
}
$customerdetails = $_POST['customerdetails'];
$staff = $_POST['staff'];
$date = date("Y-m-d H:i:s");
$quantity = $_POST['quantity'];
$sql_string = "INSERT INTO `Order`(RequestedTime,ResponsibleStaffMember,CustomerDetails)
VALUES ('$date','$staff','$customerdetails')";
$result = mysqli_query($con,$sql_string);
}
if($result)
{
echo 'Data inserted successfully';
}
else{
echo 'Data insertion failed';
}
mysqli_close($con);
?>