Jump to content

Recommended Posts

Hello,

 

I am quite new to php and I am in the middle of creating a simple shopping cart but having some trouble deciding on how to go about it.

 

My intention is to have input fields next to listed items where the user can enter a quantity for desired items, and hit a submit button once rather than having submit buttons placed next to each listed item.

 

Does anyone have any suggestions on how to perform this?

 

Up to now my logic has been to write a variable inside my while loop that increments with every row, and attaching this to each field name to make it unique e.g.

 

echo "

<tbody>

<tr>

<td>".$prodRow['item']."</td>

<td>".$prodRow['size']."</td>

<td>£".$prodRow['price']."</td>

<td><input type='text' id='qty' name='qty' maxlength='1' size='1' /></td>

<input type='hidden' name='product[".$i++."]' value='".$prodRow['id']."'>

</tr>

</tbody>";

}

 

It is proving quite difficult to pick up on the other side though, that's where I'm having the most trouble.

 

Any help would be greatly appreciated

 

P.S. I am intentionally not using any javascript on this page.

Link to comment
https://forums.phpfreaks.com/topic/50996-solved-simple-shopping-cart-php-help/
Share on other sites

What about

 

<?php
echo "
         <tbody>
         <tr>
         <td>{$prodRow['item']}</td>
         <td>{$prodRow['size']}</td>
         <td>£{$prodRow['price']}</td>
         <td><input type='text' id='qty' name='qty[{$prodRow['id']}]' maxlength='1' size='1' /></td>
         <input type='hidden' name='product[{$prodRow['id']}]' value='{$prodRow['item']}'>
         </tr>
         </tbody>";
?>

 

<?php
foreach ($_POST['product'] as $K => $P)
{
echo "$P QTY = {$_POST['qty'][$K]}<BR>";
}
?>

 

**UNTESTED and i'm tired!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.