Jump to content

Problems with Totaling values in Table using Session Variables


kerbdog

Recommended Posts

Hi I am having issues with the following code.  I cannot get the table to produce a subtotal multiplying the value of 'ITEMQTY' which is a text field in the form in which the user enters by the 'ITEMPRICE' field which value is located in a text document.

 

<h1>SHOPPING CART</h1><img src="images/cart.png" alt="Cart" width="100" height="100"/>
<a href="browse_index.php">CLICK HERE TO CONTINUE SHOPPING</a>
<?php

  if(isset($_POST['submit']))
  {

$itemname = $_POST['h1'];
//echo $_SESSION['itemname'][$itemname];
  unset($_SESSION['itemqty'][$itemname]);
  unset($_SESSION['itemprice'][$itemname]);
  unset($_SESSION['itemname'][$itemname]);
  
}
  echo "<br/><br/>";
  echo "<table border='8' cellpadding='10' >";
  echo "<tr><th>Name</th><th>Quantity</th><th>Price</th><th>Subtotal</th></tr>";
  foreach($_SESSION['itemname'] as $key => $value)
  
  $subtotal = ($_SESSION['itemprice']*($_SESSION['itemqty'];
{

echo
'<tr>
<td>'.$_SESSION['itemname'][$key].'</td>
<td><input type="text" name="t1" value='.$_SESSION['itemqty'][$key].'></td>
<td>'.$_SESSION['itemprice'][$key].'</td>
<td>'.$_SESSION['h2'][$key].'</td>
<td><form id="f1" method="post" name="f1"><input type="submit" name="submit" value = "delete"><input type="hidden" name="h1" value='.$key.'></td>
</tr>
<tr><form id="t1" method="post" action="summary.php" name="t1"><input type="submit" name="order" value="SUBMIT ORDER"></tr>';

}

  echo "</table>";
  

?>

 

[attachment deleted by admin]

I haven't gone through all of your code, but let's start with the obvious. None of the value= attributes in your form are quoted, and you're attempting to nest <form> tags, thereby invalidating the markup.

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.