Jump to content

[SOLVED] Simple shopping cart php help


Harley1979

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!

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.