2014-03-05 115 views
-1

我正在製作一個訂單,女巫將填充2個mysql表中的數據。 order和order_details 這兩個表都包含order_number列。 我創建了一個名爲order_num的第3個表,其中包含order_numbers。 我的問題是: 如何在order_num表+1中填寫order_number,order_details和order_num表中的最後一個order_numbers當用戶點擊Submit時填入? NB order_details每個訂單有多個行,所有行對於每個訂單應具有相同的order_number。 (有1到許多訂單和ORDER_DETAILS之間的關係)如何用Mysql提交最後一個id的表單提交

這裏是做了什麼 DB連接

connect.php 
<?php 

$dbhost = 'localhost'; 
$dbuser = 'user2'; 
$dbpass = 'password'; 
$dbname = 'db3'; 

$con=mysqli_connect($dbhost,$dbuser,$dbpass,$dbname); 
// Check connection 
if (mysqli_connect_errno()) 
{ 
echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
} 
?> 


entryform.php 

<?php 

    <form action="../action/custompcorder.php/" method="post"> 
<p>Order number: <input type="text" name="order_number"/> part_id: <input  type="text" name="part_id"/> quantity: <input type="text" name="quantity"/></p> 
<p>Order number: <input type="text" name="order_number2"/> part_id: <input type="text" name="part_id2"/> quantity: <input type="text" name="quantity2"/></p> 
    <input type="submit" value="Submit" /></form> 

?> 



custompcorder.php 

<?php 
include_once '../action/connect.php'; 

$sql="INSERT INTO order_details (order_number, part_id, quantity,) 
VALUES 
('$_POST[order_number]','$_POST[part_id]','$_POST[quantity]'), 
('$_POST[order_number2]','$_POST[part_id2]','$_POST[quantity2]')"; 



$sql="INSERT INTO order (order_number) 
VALUES 
('$_POST[order_number2]')"; 


?> 

Thank you for your help. 
+0

http://www.php.net/manual/en/ mysqli.insert-id.php – CBroe

回答