Jump to content

hello internetz. :) help needed with simple custom php shopping cart.


condirant

Recommended Posts

I'm working on a script at:

 

http://fadedroyalty.rmlddesigns.com

 

I'm having an issue where if a user adds one small shirt to cart, and then another shirt on the same row of the same size, and then you try to remove one of those items from the cart, I get the error:

 

"Warning: extract() [function.extract]: First argument should be an array in [....]functions.inc.php on line 35"

 

Here's the function that contains the problem, I think:

function showCart() {
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
	$items = explode(',',$cart);
	//$contents = array();
	global $contents;
	foreach ($items as $item) {
		$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
	}
	$output[] = '<form action="cart.php?action=update" method="post" id="cart">';
	$output[] = '<table>';
	foreach ($contents as $id=>$qty) {
		if($_GET['size'] == 'none') {
		$sql = "SELECT * FROM products WHERE id = ".$id;
		}
		else {
		$sql = "SELECT * FROM products WHERE id = '".$id."'";
		}
		$result = $db->query($sql);
		$row = $result->fetch();
		extract($row);
		$output[] = '<tr>';
		$output[] = '<td><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
		$output[] = '<td>'.$itemname.'</td>';
		$output[] = '<td>$'.$price.'</td>';
		$output[] = '<td><input type="text" name="qty'.$id.'" value="'.$qty.'" size="3" maxlength="3" /></td>';
		$output[] = '<td>$'.($price * $qty).'</td>';
		$total += $price * $qty;
		$output[] = '</tr>';
	}
	$output[] = '</table>';
	if($total <= 74) { $orig_total = $total; $total = $total+5.95;  
	$output[] = '<p>Total: <strong>$'.$orig_total.'. With shipping($5.95): <strong>$'.$total.'</strong></p>';
	}
	else {  
	$output[] = '<p>Your order is over $75, so shipping is free. Grand total: <strong>$'.$total.'</strong></p>';		
	}
	$output[] = "<div><button type='submit'>Update cart</button><button type='button' onClick=\"window.location = 'checkoutp1.php'; \">Checkout</button></div>";
	$output[] = "</form>";
	$output[] = "<script>
if(window.location != 'http://fadedroyalty.rmlddesigns.com/cart.php?action=update) { document.forms['cart'].submit(); }
</script>";
} else {
	$output[] = "<p>You shopping cart is empty.</p>";
}
return join('',$output);
}

 

 

Anybody that helps me solves this, I greatly appreciate your help, and if you want to become business partners I will pay you for work when I get it.

Thanks anyone!! :)

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.