Jump to content

I'm trying to use foreach with POST with out any luck, please help if you can.


Presto-X

Recommended Posts

Hey guys I could really use your help in a bad way...

 

I created a basic order form with a list of checkboxes and textfields for quantity, the form looks something like this:

 

[checkbox] Product Name 1 [textfield for quantity]

[checkbox] Product Name 2 [textfield for quantity]

[checkbox] Product Name 3 [textfield for quantity]

 

You can view the page here: http://www.sierrarescue.com/index.php?option=com_instructors&step=1

 

This is the code that I'm using to create the form loop on the product page:

 <?PHP while ($products = mysql_fetch_object($products_sql)){
  ?>
    <tr>
      <td width="25"><input type="checkbox" name="price" id="checkbox<?php echo $products->id; ?>" value="<?php echo $products->price; ?>" /></td>
      <td><label for="checkbox<?php echo $products->id; ?>"><?php echo $products->name; ?></label></td>
      <td width="65" nowrap="nowrap">$<span id="price<?php echo $products->id; ?>"><?php echo $products->price; ?></span> </td>
      <td width="20"><input name="id<?php echo $products->id; ?>" id="quantity<?php echo $products->id; ?>" type="text" size="3" value="0" onFocus="if(this.value=='0'){this.value=''};" onBlur="if(this.value==''){this.value='0'};" /></td>
    </tr>
  <?PHP } ?>

 

Now for my problem, I am not sure the best way to get this data on the next page, I have been trying to use

foreach($_POST as $name => $value){
$name1 = str_replace("_"," ",$name);
$nameSTR = substr($name1,0,;
  if($name=="totalcost"){$totalcost=$value;}
  if($nameSTR=="quantity"){$quantity=$value;}
  if(($nameSTR=="subtotal")or($nameSTR=="shipping")or($nameSTR=="quantity")or($nameSTR=="submit")or($name=="totalcost")){
    # If the fields name string = subtotal, shipping or quantity Do Nothing and move on...
  }else{
    print "<tr><td nowrap=\"nowrap\" class=\"productName\">$name1</td><td width=\"18%\" align=\"right\" class=\"productName\">&#36;$value $quantity</td></tr>";
  }
}

with out any luck it is not working as I tought it would, it's doing a new row for each posted item and I want it to display the product name, price and quantity all on one line.

 

 

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.