gpt4 book ai didi

php MySql 全局变量

转载 作者:行者123 更新时间:2023-11-29 17:55:34 25 4
gpt4 key购买 nike

我正在尝试获取最后一个订单 ID 并将其设置在变量中,以便我能够在另一个 Order_Items 表中设置此 ID

$generatedId=0;
if(isset($_POST['newOrder'])){
$costumerID = $_POST['CostumerID'];
$orderDateID = $_POST['orderDateID'];
$deliveryDateID = $_POST['deliveryDateID'];
$orderRemeraks = $_POST['orderRemeraks'];
$orderType = $_POST['orderType'];

echo $costumerID;
$query = "INSERT INTO `orders` (`costumerName`,`dateOfOrder`,`dateOfDelivery`,`remarks`,`type`,`status`)
VALUES ('$costumerID','$orderDateID','$deliveryDateID','$orderRemeraks','$orderType', 'open');";
$insertRow = $mysqli->query($query) or die ($mysqli->error.__LINE__);
$generatedId = $mysqli->insert_id;
if($insertRow){
$GLOBALS['generatedId'] = $mysqli->insert_id;
$msg = 'New Order was added ';
echo $msg;
echo $generatedId;
}

}

if(isset($_POST['newItem'])){
$item_Number = $_POST['item_Number'];
$itemQty = $_POST['itemQty'];
$itemKg = $_POST['itemKg'];
$itemRemarks = $_POST['itemRemarks'];
echo $generatedId;
$query = "INSERT INTO `item_number` (`order_id`, `item_number`, `quantity`,`quantity_kg`,` remarks`,`filling_status`)
VALUES('$generatedId', '$item_Number','$itemQty','$itemKg','$itemRemarks','not',);";
$insertRow = $mysqli->query($query) or die ($mysqli->error.__LINE__);

if($insertRow){
echo 'New Item was added ' ;
}
}

问题是 $genertedId 打印时初始值为 0,因为我无法将其放入 order_items 表中,但在第一次(就在 echo $msg 之后) ,打印时返回真实值;

谢谢

最佳答案

$generatedId = mysqli_insert_id($mysqli); 
if($insertRow){
$GLOBALS['generatedId'] = $generatedId;
$msg = 'New Order was added ';
echo $msg;
echo $generatedId;
}

关于php MySql 全局变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48883858/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com