2016-10-17 113 views
-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); 
    ?> 

回答

相關問題