아마 다른 테이블에 거기 밖으로 개발자를위한 간단한을 넣어잡아 하나 개의 테이블에서 마지막 삽입 ID는
나는 '주문'테이블에 대한 ORDER_ID 및 ORDER_NAME를 삽입하는 코드가 있습니다
<?php
// start the session handler
require_once('dbfunction.php');
//connect to database
$conn = DB();
require_once('header.php');
//should we process the order?
if (isset($_POST['process'])) {
$order_name = $_POST['order_name'];
//create initial order
$stmt = $conn2->prepare("INSERT INTO orders (order_name) VALUES (?)");
//bind the parameters
$stmt->bind_param('s', $order_name);
// Execute query
$stmt->execute();
을
이제 주문 항목을 order_items 테이블에 삽입하려고합니다. '주문'테이블에 삽입하고 order_items와 함께 'order_items'테이블에 추가 할 때 생성 된 것과 동일한 ID를 유지하는 것 같습니다. 여기 내 코드입니다 :
//this gets the most recent auto incremented ID from the database - this is the order_id we have just created
$order_id = mysql_insert_id();
//loop over all of our order items and add to the database
foreach ($_SESSION['order'] as $item) {
$prod_id = $item['prod_id'];
$quantity = $item['quantity'];
$prod_type = $item['prod_type'];
$stmt = $conn2->prepare("INSERT INTO order_items (order_id, prod_id, quantity, prod_type) VALUES (?, ?, ?, ?)");
//bind the parameters
$stmt->bind_param('iiis', $order_id, $prod_id, $quantity, $prod_type);
// Execute query
$stmt->execute();
}
echo "<p class='black'>Order Processed</p>";
어떤 버전의 SQL입니까? –
준비된 문장으로 된 sqli – user1227124
멋지네요, 뭐가 잘못 됐나요? (질문?) –