Jump to content

Problem with Code... HMMmmm...


bri0987

Recommended Posts

My page updates fine when I use the pulldown menus BUT The problem is that when the Qty is at higher numbers for some reason I have to click the REMOVE button several times. The amount of times I click the Remove button does not match the Qty ... It seems to always be a random amount of times I have to click the Remove button for the Item to be removed...

 

One time I had to click the Remove Button 11 times before it removed the item? It is very strange. And Some time I only have to click it once.

 

Can anyone please look at my code below and see if you find anything that would cause this problem.....

 

 

This code is at the top of my CART.PHP page:

if (isset($_GET['action'])) {
if ($_GET['action'] == "RemoveItem") {
	$Remove_Item = 1;
	$UpdateQty_okay = 0;
	$qty_okay = 0;

	if (isset($_GET['Removeid'])) {
		$Remove_id = 1;
		$RemoveSCID = $_GET['Removeid'];
	} else {
		$Remove_id = 0;
		$RemoveSCID = $_GET['Removeid'];
	}

} elseif ($_GET['action'] == "UpdateQty") {
	$UpdateQty_okay = 1;
	$Remove_Item = 0;
	$Remove_id = 0;

	if (isset($_GET['id'])) {
		$SC_ID = $_GET['id'];
		$id_okay = 1;
	} else {
		$id_okay = 0;
	}
	if (isset($_GET['qty'])) {
		$NewQty = $_GET['qty'];
		$qty_okay = 1;
	} else {
		$qty_okay = 0;
	}
} else {
	// Do nothing ... The Action was not Remove or Update...
}
// Remove Item from Shopping Cart Database
if (($Remove_Item == 1) && ($Remove_id == 1)) {
	$query_delete = "DELETE FROM tblshoppingcart WHERE ShoppingCart_ID = {$RemoveSCID}";
	mysql_select_db($database_DM_database, $DM_database);
	$Results = mysql_query($query_delete, $DM_database) or die(mysql_error());

	//header("Location: cart.php");

	// Update QTY into Shopping Cart Database		
} elseif (($UpdateQty_okay == 1) && ($id_okay == 1) && ($qty_okay == 1)) {
	$query = "UPDATE tblshoppingcart SET qty = {$NewQty} WHERE ShoppingCart_ID = {$SC_ID}";
	mysql_select_db($database_DM_database, $DM_database);
	$Result = mysql_query($query, $DM_database) or die("query='$Result '<br>".mysql_error());

	header("Location: cart.php");

} else { 
	// Do Nothing  ... The One of the Varibles were ZERO...
}
} else {
// Do Nothing ... The Varible $_GET['action'] was NOT SET.
}

 

This is the Code for the JavaScript that sends the page:

<script language="JavaScript">
function UpdateQty(item)
{
	itemId = item.name;
	newQty = item.options[item.selectedIndex].text;

	document.location.href = 'cart.php?action=UpdateQty&id='+itemId+'&qty='+newQty;
}

function RemoveItem(item)
{
	scId = item.name;

	document.location.href = 'cart.php?action=RemoveItem&Removeid='+scId;
}

</script>

 

This is the code of the Pulldown menu that uses the the UpdateQty from the Javascript:

<select name="<?php echo $row_rsSCProduct["ShoppingCart_ID"]; ?>" onChange="UpdateQty(this)">
<?php 
	for($i = 1; $i <= 20; $i++)	{
		echo "<option "; 
		if($row_rsSCProduct["qty"] == $i) {	
			echo " SELECTED ";
			$RealQTY = $i;
		}
		echo ">" . $i . "</option>";
	}
?>
    </select>

 

This is the code for the Remove button that uses the Remove Javascript code:

<input name="<?php echo $row_rsSCProduct["ShoppingCart_ID"]; ?>" type="image" src="../images/product_remove_cart.jpg" alt="Remove Item" onClick="RemoveItem(this)"/>

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.