Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 更新数据表中的数量_Php_Mysql_Database - Fatal编程技术网

Php 更新数据表中的数量

Php 更新数据表中的数量,php,mysql,database,Php,Mysql,Database,我试图建立一个订单,客户输入任何数量,因此我的库存得到更新,从而为下一个客户保持当前的金额,我一直在努力想出正确的代码,但迄今为止没有运气。任何建议都将不胜感激,以下是我的代码: <?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 (

我试图建立一个订单,客户输入任何数量,因此我的库存得到更新,从而为下一个客户保持当前的金额,我一直在努力想出正确的代码,但迄今为止没有运气。任何建议都将不胜感激,以下是我的代码:

<?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');
    ?>  

为完美的人寻找完美的小部件?浏览我们的小型但原创的
要购买的产品列表。或者,您可以通过我们的联系页面与我们联系,我们的一个团队将获得
尽快给你回电话。
小部件订单小部件数量成本脱水水“/>18.50美元玻璃杆“/>28.50美元

您永远不会获得
$productquantity
数组。您的陈述将评估为正确或错误:

$quantityarray = ((isset($_POST['f_wa']) ? $_POST['f_wa'] : '') || (isset($_POST['f_gl']) ? $_POST['f_gl'] : ''));                                            
此语句中的
|
表示如果第一条语句或第二条语句为true,则将
$quantityarray
设置为true,否则将
$quantityarray
设置为false

您应该
var\u dump($quantityarray)
才能看到这一点