gpt4 book ai didi

php - 更新数据表中的数量

转载 作者:行者123 更新时间:2023-11-30 01:29:36 25 4
gpt4 key购买 nike

我正在尝试设置一个订单,客户可以在其中输入任何数量,因此我的库存会得到更新,从而为下一个客户保留当前数量,我一直在尝试提供正确的代码,但到目前为止没有运气。任何建议将不胜感激,这是我的代码:

<?php
session_start(); //Lets start a session! This is the index page
$_SESSION["access"] = "My_session";
//We need a header right, well here it is?
define ("TITLE", "Products page");
include('templates/header.html');
?>
<h2 class="intro">
Looking for the perfect widget for the perfect person? Browse through our small but original
list of products to purchase. Alternatively you can contact us through our contact page and one of our team will get
back to you as soon as possible.
WIDGET ORDER FORM Widget Quantity Cost Dehydrated water " /> $ 18.50 Glass Stems " /> $ 28.50

<?php
// Get the values from the $_POST array:
$quantityarray = ((isset($_POST['f_wa']) ? $_POST['f_wa'] : '') || (isset($_POST['f_gl']) ? $_POST['f_gl'] : ''));

include 'connection.php';

# Define the SQL statement
$query = 'Select ProductID, InStock from Inventory ORDER BY ProductID';
if ($result = mysql_query($query)) {
while ($row = mysql_fetch_array($result)) {
$currentnum = $row['InStock'] - $quantityarray[$row['ProductID']];
$prodid = $row['ProductID'];
// execute a SQL statement to update the InStock number
$query = "UPDATE Inventory SET InStock = $currentnum WHERE ProductID=$prodid";
sendquery($query);
}
}

function sendquery($query)
{
if (@mysql_query($query)) {
print '<p>Table populated.</p>';
} else {
print '<p style="color:red;">Error executing SQL statement: <br/>' . mysql_error() . '.</p>

<p>The statement being run was: ' . $query . '</p>';
}
}

?>
<?php
//To conclude we also need the footer, don't we?.
include('templates/footer.html');
?>

最佳答案

您永远不会获得 $productquantity 数组。您的陈述将评估为真或假:

$quantityarray = ((isset($_POST['f_wa']) ? $_POST['f_wa'] : '') || (isset($_POST['f_gl']) ? $_POST['f_gl'] : ''));                                            

此语句中的 || 表示如果第一个语句或第二个语句为 true,则将 $quantityarray 设置为 true,否则设置 $quantityarray > 为假

您应该var_dump($quantityarray)来查看此内容。

关于php - 更新数据表中的数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17626550/

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