簡體   English   中英

last_id如何工作?

[英]How last_id works?

插入客戶sql,其他未插入。 救命。 謝謝

我有用於customer_tbl,transaction_tbl和order_tbl的sql。

customer_no,transaction_no和orderlist_no是A_I。

到目前為止,這是我的代碼。

 $x=0;
 while ($x!=5) {
    $product_sku[$x] = $_POST['productsku[$x]'];
    $quantity[$x] = $_POST['productqty[$x]'];
    $x=$x+1;
 }

 $sqlc = "INSERT INTO customer_tbl(customer_name, fb_url, mobile_no, email_address, address) VALUE ('$customer_name', '$fb_url', '$mobile_no', '$email', '$address');";

 mysqli_query($conn, $sqlc);
 $last_id = mysqli_insert_id($conn);


 $sqlt = "INSERT INTO transaction_tbl(customer_no, transaction_type, status, transaction_date, deadlinepay_date, payment_mode, delivery_option) VALUE ('$lastid', 'OL-', '1', CURRENT_TIMESTAMP(), '$deadlinepay_date', '$payment_mode', '$shipping_option');";

 mysqli_query($conn, $sqlt);
 $last_id = mysqli_insert_id($conn);

 $x=0;
 while ($x!=5) {
    if (!empty($product_sku[$x])) {
        $sqlo = "INSERT INTO order_tbl(transaction_no, product_sku, quantity) VALUES ('$last_id', '$product_sku', '$quantity');";
        mysqli_query($conn, $sqlio);
    }
    $x=$x+1;
 }

在您的代碼中,您有$last_id = mysqli_insert_id($conn); 但是在查詢中,您有...VALUE ('$lastid'...

因此,將$lastid更改$lastid $last_id或其他方法。

您應該保持命名變量的一致性,以免將來造成混淆。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM