Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

captainmeowtron

macrumors member
Original poster
Dec 1, 2008
43
0
Please take a look at my site, and let me know if you have any advice on the following:
-when removing items from the cart, they update as quantity=0, but I'd like them to disappear from the cart altogether. I can point to the place in my shopping cart script where it should happen, but I don't know exactly what to do.
-In Firefox, the session is not carrying across different pages. I've tried various things, but they aren't working.
Any suggestions? As you can see, I'm a small business owner trying to save a lot of money by doing this myself. I'm not an expert by any stretch, and most of the code is copied, pasted, and stitched together through trial and error. Constructive criticism is much appreciated. Please keep in mind that I'm fumbling around with this and I don't know php at all. Any stylistic suggestions are welcome also.
http://www.oonaghnaturals.com
 
Okay, maybe something less time consuming then. Any advice on how to specify price for each option value, instead of the same price for all option values? Here's what I've used for the first form:
Code:
<tr>
		<td align="center"><img src="masque.jpg"></td>
		<td width="450"><center><FONT SIZE="4">Dark Earth facial masque</center></font>
<p></p>

Oonagh's Dark Earth Facial Masque is the remedy for breakouts and large 
                                pores. A special blend of cacao, honey powder, frankincense, and tea tree 
                                oil acts as a natural antibacterial. Green tea and cucumber peel extracts soothe 
                                and firm the skin. Results are immediately visible. High in natural antioxidants. 2 oz. $15</p></td>
		<td><form method="post" action="ShoppingCart.php" >
<select name="type"><option value=""> </option><option value="Dark Earth facial masque">Dark Earth facial masque</option>
</select>
<input name="Price" type="hidden" value="15.00" />
<input name="cmd" type="hidden" id="cmd" value="1" />
<input type="Submit" name="Submit" value="add to cart" /></form>
On the second form, I want to make small and large options different prices. I tried making price an if/else statement, but that didn't seem to work, or I did it incorrectly.
Code:
</td>
	</tr>
	<tr>
		<td align="center"><img src="kinky kreme.jpg"></td>
		<td width="450"><center><FONT SIZE="4">Kinky Kreme hair gloss</center></font>
<p></p>

Wild verbena, a time-tested African hair treatment, forms the base for this natural 
                                hair conditioner. Coconut oil, vitamin e, soy butter, and natural fragrance moisturize 
                                hair deep down, preventing breakage and promoting longer, smoother hair. 1 oz and 4 oz jars. $10, $15.</td>
		<td><form method="post" action="ShoppingCart.php" >
<select name="type"><option value=""> </option><option value="small kinky kreme">small kinky kreme</option><option value="large kinky kreme">large kinky kreme</option>
</select>
<input name="Price" type="hidden" if (option value="small kinky kreme") {value="10.00 } else {value="15.00"} />
<input name="cmd" type="hidden" id="cmd" value="1" />
<input type="Submit" name="Submit" value="add to cart" /></form>
</td>
	</tr>
Any ideas?
Here's the code if you want to see it in action (or inaction I guess):
http://www.oonaghnaturals.com/natural products.html
 
You need to use PHP brackets when using PHP inside HTML. The following won't work because it's simply invalid HTML,
HTML:
<input name="Price" type="hidden" if (option value="small kinky kreme") {value="10.00 } else {value="15.00"} />
Instead, you'll want something like,

PHP:
<input name="Price" type="hidden" value="<?php
  echo ($_POST['type'] == "small kinky kreme") ? 10.00 : 15.00;
?>" />
 
to unset a value you can use php's unset()

it's basicly.

if your items are called by index (item[x] where x is an integer >= 0) then you might have issues with the removed indexes - use foreach instead (for instance).

good luck.

PHP:
<html>
<?php
$vars = array("foo"=>1, "foo2"=>2);
echo "before<br /><pre>";
print_r($vars);
echo "</pre>";

unset($vars["foo"]);

echo "after<br /><pre>";
print_r($vars);
echo "</pre>";

?>
</html>
 
PHP:
<input name="Price" type="hidden" value="<?php
  echo ($_POST['type'] == "small kinky kreme") ? 10.00 : 15.00;
?>" />

That's not working at all, I'm afraid. Is it one of those googled answers? :)
 
PHP:
<html>
<?php
$vars = array("foo"=>1, "foo2"=>2);
echo "before<br /><pre>";
print_r($vars);
echo "</pre>";

unset($vars["foo"]);

echo "after<br /><pre>";
print_r($vars);
echo "</pre>";

?>
</html>
What if I don't have an array? I have a loop. Is there still a way to use unset? Here's the section of the script:
Code:
function UpdateCart($_POST,$Session_Prefix)
{
  for ($updatecnt = 1; $updatecnt < ($_SESSION[$Session_Prefix.'Item_Count'] + 1); $updatecnt++)
  {
    	$updatequantity = "quantity".$updatecnt;
	$updateremove = "remove".$updatecnt;
	
	if (is_numeric($_POST[$updatequantity]))
	{
	  $_SESSION[$Session_Prefix.$updatequantity] = $_POST[$updatequantity];
	}

	if (is_numeric($_POST[$updateremove]))
	{
	  if ($_POST[$updateremove]="1")
	  {
	    $_SESSION[$Session_Prefix.$updatequantity] = 0;
	  }
	} 
}
  $gaps = "1";
  while ($gaps != 0)
  {
   $gaps = "0";
 	  if ($nextrow < ($_SESSION[$Session_Prefix.'Item_Count'] + 1))
	  {
  		// Copy NextRow Info Down To This Row (and delete NextRow's title)
		$_SESSION[$Session_Prefix.$updatetitle] = $_SESSION[$Session_Prefix.$updatetitlenext];
		$_SESSION[$Session_Prefix.$updateshippinga] = $_SESSION[$Session_Prefix.$updateshippinganext];
		$_SESSION[$Session_Prefix.$updateprice] = $_SESSION[$Session_Prefix.$updatepricenext];
		$_SESSION[$Session_Prefix.$updatequantity] = $_SESSION[$Session_Prefix.$updatequantitynext];
		$_SESSION[$Session_Prefix.$updatetitlenext] = "";
	  } else
	  {	   
		$_SESSION[$Session_Prefix.$updatetitle] = "";
		$_SESSION[$Session_Prefix.$updateshippinga] = "";
		$_SESSION[$Session_Prefix.$updateprice] = "";
		$_SESSION[$Session_Prefix.$updatequantity] = "";
		$_SESSION[$Session_Prefix."Item_Count"] = $previousrow;
		}       
  } 
  header("location:ShoppingCart.php?u");
}
I tried using
PHP:
if ($_POST[$updateremove]="1")
	  {
	    unset $Item_Row = $_SESSION[$Session_Prefix.'Item_Count'];
	  }
and also
PHP:
if ($_POST[$updateremove]="1")
	  {
	    unset $previousrow;
	  }
and neither of those work. I don't get it. Any ideas?
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.