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 

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<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>";

?>

Link to comment
Share on other sites

<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>";

?>

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.