Jump to content

Setting Default Value


TheJoey

Recommended Posts

ahh sorry if i didnt explain myself well guys.

i tend to do that sometimes.

I have a shopping cart and when i add a item it displays

 

item name :  (Nothing here as 1) : price

 

then when i click add again it adds it as

 

item name : 1 : price

 

where i want 1 to be a incremental 

When im adding to my shopping cart.

It is being display as an empty value, inside quantity when its really a 1.

So then the incremental is then out of wack the next time i add a item. so if instead of it being display as 2 it is being displayed as 1.

Because of the fact that its starting off as NULL.

 

When im adding to my shopping cart.

It is being display as an empty value, inside quantity when its really a 1.

So then the incremental is then out of wack the next time i add a item. so if instead of it being display as 2 it is being displayed as 1.

Because of the fact that its starting off as NULL.

 

 

So post the relevant code that creates an item in your cart. We can't do anything but post examples without the relevant code.

<html>
<body>
<?php


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

  if($_SESSION['item']==$_POST['h1'])
{
  $_SESSION['qty'] = $_SESSION['qty'] + 1;
}
else
{
  $_SESSION['item'] = $_POST['h1'];
  $_SESSION['price']= $_POST['h2'];
}
$_SESSION['itemprice'][$_SESSION['item']] = $_SESSION['price'];
  $_SESSION['itemqty'][$_SESSION['item']] = $_SESSION['qty'];
  $_SESSION['itemname'][$_SESSION['item']] = $_SESSION['item'];

}




?>
<table>
<tr>
<td>
</td>
<td>ITEM info here</td></tr>
<tr><td><form action="cartpost.php" method="post"><input type="submit"
name="submit" value="ADDING"/><input type="hidden" name="value"
value="itemid" /><input type="hidden" name="value1" value="7000"/></form> </td></tr>
</table>

<a href="cart.php">View your cart</a>
</body>
</html>

 

this just outputs into the minicart

 

<?php


  echo "The shopping cart looks as follows:--";

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

  $itemname = $_POST['value'];
  unset($_SESSION['itemqty'][$itemname]);
  unset($_SESSION['itemprice'][$itemname]);
  unset($_SESSION['itemname'][$itemname]);
  }

  echo "<br/><br/>";
  echo "<table border='1'>";
  echo "<tr><th>itemname</th><th>Qty</th><th>Price</th></tr>";
  if (isset($_SESSION['itemname']))
  {
  foreach($_SESSION['itemname'] as $key=>$value)

{

echo
'<tr><td>'.$_SESSION['itemname'][$key].'</td><td>';
$_SESSION["itemqty"][$key];
echo $_SESSION["itemqty"][$key];
echo '</td><td>'.$_SESSION['itemprice'][$key].'</td><td><form
id="f1" method="post" name="f1"><input type="submit" name="submit" value =
"delete"><input type="hidden" name="value" value='.$key.'></td></tr>';

}
}



  echo "</table>";

?>

<html>
<body>
<?php


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

  if($_SESSION['item']==$_POST['h1'])
{
  $_SESSION['qty'] = $_SESSION['qty'] + 1;
}
else
{
  $_SESSION['item'] = $_POST['h1'];
  $_SESSION['price']= $_POST['h2'];
}
$_SESSION['itemprice'][$_SESSION['item']] = $_SESSION['price'];
  $_SESSION['itemqty'][$_SESSION['item']] = $_SESSION['qty'];
  $_SESSION['itemname'][$_SESSION['item']] = $_SESSION['item'];

}




?>
<table>
<tr>
<td>
</td>
<td>ITEM info here</td></tr>
<tr><td><form action="cartpost.php" method="post"><input type="submit"
name="submit" value="ADDING"/><input type="hidden" name="value"
value="itemid" /><input type="hidden" name="value1" value="7000"/></form> </td></tr>
</table>

<a href="cart.php">View your cart</a>
</body>
</html>

 

this just outputs into the minicart

 

<?php


  echo "The shopping cart looks as follows:--";

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

  $itemname = $_POST['value'];
  unset($_SESSION['itemqty'][$itemname]);
  unset($_SESSION['itemprice'][$itemname]);
  unset($_SESSION['itemname'][$itemname]);
  }

  echo "<br/><br/>";
  echo "<table border='1'>";
  echo "<tr><th>itemname</th><th>Qty</th><th>Price</th></tr>";
  if (isset($_SESSION['itemname']))
  {
  foreach($_SESSION['itemname'] as $key=>$value)

{

echo
'<tr><td>'.$_SESSION['itemname'][$key].'</td><td>';
$_SESSION["itemqty"][$key];
echo $_SESSION["itemqty"][$key];
echo '</td><td>'.$_SESSION['itemprice'][$key].'</td><td><form
id="f1" method="post" name="f1"><input type="submit" name="submit" value =
"delete"><input type="hidden" name="value" value='.$key.'></td></tr>';

}
}



  echo "</table>";

?>

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.