2013-07-13 4 views
0

고객이 수량을 입력하고 그 결과 인벤토리가 업데이트되어 다음 고객의 현재 금액을 유지하는 주문 양식을 설정하려고하는데 올바른 코드를 제시하려고했습니다. 그러나 운 없음 지금까지.데이터 테이블의 수량 업데이트

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

답변

0

당신은 결코 $productquantity 배열을 받고되지 않습니다 : 어떤 조언이 크게 감사합니다, 여기에 내 코드입니다. 귀하의 성명을 평가합니다 true 또는 false : 첫 번째 문 또는 두 번째 문은 사실 그때 다른 true로 $quantityarray가 거짓

당신이해야 var_dump($quantityarray)$quantityarray을 설정하는 경우이 문에

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

|| 의미 이것 좀 봐.

관련 문제