2013-10-10 22 views
-1

我使用PHP創建一個基本的購物車無樣式頁面上工作。但是,該頁面是使用下拉式構建的,由於產品數量的原因,難以使用該下拉式應用。與量創建一個產品列表,每「添加到購物車」按鈕

我想改變它,每個項目都有自己的量&添加到購物車按鈕。不幸的是,我試過的所有不同的配置總是給我同樣的錯誤 - 列'product_id'不能爲空。我已經能夠讓它停止給我這個錯誤,但它也不會傳遞價格&產品名稱。

這裏的原代碼(只是部分創建我試圖修改的部分,讓我知道,如果你需要更多):

<form action="<?php echo $editFormAction; ?>" method="post"> 
    <p><label for="product_name">Product Name:</label><br /> 
    <select name="product_name"> 
     <?php 
      do { 
     ?> 
     <option value="<?php echo $row_getProducts['product_id']?>"> 
     <?php echo $row_getProducts['store_name']?></option> 
     <?php 
      } while ($row_getProducts = mysql_fetch_assoc($getProducts)); 
       $rows = mysql_num_rows($getProducts); 
       if ($rows > 0) { 
       mysql_data_seek($getProducts, 0); 
      $row_getProducts = mysql_fetch_assoc($getProducts); 
       } 
     ?> 
     </select></p> 
     <p><label for="quantityt">Quantity:</label><br /> 
     <input type="text" name="quantity" value="" /></p> 
     <input type="submit" name="submit" value="Add Item to Cart" /> 
     <input type="hidden" name="total" value="" /> 
     <input type="hidden" name="MM_insert" value="first_item" /> 
    </form> 

此代碼不會返回一個錯誤,但它只有經過量一個時間:

<p><label for="product_name">Product Name:</label><br /><br /> 

    <?php 
    do { 
    ?> 
    <input name="check1" type="checkbox" /> <?php echo $row_getProducts['product_id']?> <?php echo $row_getProducts['store_name']?> 1 <?php echo $row_getProducts['price']?> <br /> 

    <p><label for="quantityt">Quantity:</label><br /> 
    <input type="text" name="quantity" value="" /></p> 
    <input type="submit" name="submit" value="Add Item to Cart" /> 
    <input type="hidden" name="total" value="" /> 
    <input type="hidden" name="MM_insert" value="first_item2" /> 

<br /> 

    <?php 
    } while ($row_getProducts = mysql_fetch_assoc($getProducts)); 
     $rows = mysql_num_rows($getProducts); 
     if ($rows > 0) { 
      mysql_data_seek($getProducts, 0); 
      $row_getProducts = mysql_fetch_assoc($getProducts); 
     } 
    ?> 
</p> 
</form> 

你可以沿着傳遞任何想法,將不勝感激!

謝謝,

j。

+0

你是什麼意思,而不是一個下拉菜單,你只想要一個列表或東西嗎? – Matheno

+0

你從哪裏得到錯誤?保存到數據庫時?如果是這樣,那麼提供代碼來獲取輸入並保存數據。 – crafter

+0

@marijke是的,只是一個複選框旁邊的每個項目,數量箱,並添加到購物車按鈕列表。謝謝! – caketime

回答

0

你可以在下拉改變這樣的事情:

<input type='text' name="<?php echo $row_getProducts['product_id'] ?>" value="<?php $row_getProducts['store_name'] ?>"> 

並添加量按鈕與PRODUCT_ID一起後面。

+0

非常感謝您的幫助,@marijke。我在原始文章中添加了一些代碼,但不會給我一個錯誤,但它也不會正確地轉到購物車。它不會將價格或名稱傳遞給購物車,只是數量,並且只能使用一次 - 如果我嘗試添加另一個項目,則會替換它。 – caketime

相關問題