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]

Link to comment
Share on other sites

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.