를 사용하여 데이터베이스에서 여러 행을 삽입 내가 product_name
및 jquery
의 도움으로 product
의 quantity
에 대한 input field
더 추가 할 수있는 형태를 만들어,이 양식에서 더 많은 입력 필드를 추가 할 수 있습니다 demo입니다.PHP 양식
문제는 양식을 제출하면 product
은 내 데이터베이스에 제출되며 나머지 제품은 제출되지 않습니다.
이
<form action="order.php" method="post">
<div class="newOrder">
<p><span>Date</span><input type="date" value="2014-12-01" name="date" /></p>
<p><span>Name</span>
<select name="customer_name">
<?php
while($customer = mysqli_fetch_assoc($customers_set)){ ?>
<option><?php echo $customer['customer_name']; ?></option>
<?php } ?>
<?php mysqli_free_result($customers_set); ?>
</select>
</p>
<div id="input_fields">
<p><span>Product Description</span>
<select name="product_description">
<?php
while($product = mysqli_fetch_assoc($product_set)){ ?>
<option><?php echo $product['product_description']; ?></option>
<?php } ?>
<?php mysqli_free_result($product_set); ?>
</select>
<input value="0" type="text" name="quantity" />
</p>
</div>
<a href="#" class="more">Add More Product</a>
<p class="radio">
<input type="radio" name="status" value="0" checked />For delivery
<input type="radio" name="status" value="1" />For payment confirmation
<input type="radio" name="status" value="2" />Reserved items
</p>
<input type="submit" name="submit" value="Create Order" />
</div>
</form>
어떤 몸은 내 쿼리
<?php
if(isset($_POST['submit'])){
//process the form
$date = $_POST["date"];
$customer_name = $_POST["customer_name"];
$product_description = $_POST["product_description"];
$quantity = $_POST["quantity"];
$status = $_POST["status"];
$query = "
INSERT INTO orders (
date, customer_name, product_description, quantity, status
) VALUES (
'$date', '$customer_name', '$product_description',$quantity,$status
)";
$order_set = mysqli_query($connection, $query);
if($order_set){
redirect_to("index.php");
}
} else {
// failed
}
?>
내 양식 input field
의 모든 product
및 quantity
입력이 데이터베이스에 저장됩니다 제출하는 방법을 어떤 생각했다입니다.
내가 그냥 루프에서 값 목록을 구축하고 구축하고 전체 쿼리 – Strawberry
감사의 위해를 실행할 필요가 있다고 생각 : 데이터베이스에 한 번에 삽입 여러 행을 위해 여기 봐 당신의 제안,하지만 내 PHP 학습이 너무 제한되어 있기 때문에 어디서부터 시작 해야할지 모르겠다 ..하지만 어쨌든 고마워요 – jhunlio