Page 1 of 1

[SOLVED] 'Remove' section not removing until clicked a secon

Posted: Tue Aug 24, 2004 8:43 pm
by dardsemail
I have listed code below. The problem I'm having is with the 'remove' section. When I try to remove an order, the order still appears on the page until I click on 'remove' a second time.

Any suggestions?

Code: Select all

<?php
ob_start();
session_start();
$authorizedUsers = "visitor,admin";
$donotCheckaccess = "false";
$_SESSION['prevUrl']="orders.php";

	
if (isset($_SESSION['frm_username']))
	{	
		showPage();
	}
	else 
	{
		header("Location:login.php");
	}

switch(@$_GET["action"]) 

	{
		case "remove_orders":
		{
			RemoveOrder($_GET["orderID"]);
		}
	}

	function RemoveOrder($orderID)
	{
		// Uses an SQL delete statement to remove an item from
		// the users cart

		include ('connection/db.php');
				
		mysql_query("DELETE FROM orders WHERE orderID = $orderID");
		showPage();
	}

function showPage()
{

error_reporting (E_ALL);
		
function showOrders()
{

	include ('connection/db.php');
	$orderQuery="SELECT * FROM orders WHERE userID='" . $_SESSION['userID'] . "'";
	//Retrieve the item details of the cart 
	$result = mysql_query ($orderQuery) or die("ERROR, ERROR!".mysql_error()); 
	$numRows = mysql_num_rows ($result);
	
	if ($numRows == 0)
	{
				echo "<h4><align =",center,">You do not have any open orders at present.</h4><br />";
		}
		else
		{
				echo "
            <table align=",center,">
			<tr>
				<td><h1>Your Shopping Cart</h1>
				</td>
				</tr>
              <tr>
                <td><h4>Order ID</h4></td>
                <td><h4>Date Submitted</h4></td>
                <td><h4>Date Shipped</h4></td>
                <td><h4>Total Value of Order</h4></td>
				<td><h4>Remove?</h4></td>
              </tr>";		
	//Go through each of the items in the cart
	while ($row=@mysql_fetch_array($result))
	{

		//Show the details of the item
		echo "\n\t<td><h3>";
		echo $row["orderID"];
		echo "</h3></td>";
		
		//Show the details of the item
		echo "\n\t<td><h3>";
		echo $row["dateSubmitted"];
		echo "</h3></td>";
		
		//Show the details of the item
		echo "\n\t<td><h3>";
		echo $row["dateShipped"];
		echo "</h3></td>";
		
		//Show the details of the item
		echo "\n\t<td><h3>";
		echo $row["total"];
		echo "</h3></td>";
		
		//Link to remove item - blank for now
		echo "\n\t<td>";		
		echo "<a href=orders.php?action=remove_orders&orderID=",$row["orderID"],">Remove</a>";
		echo "</td>";
		echo "\n</tr>";				
	}
	}
}


?>

Posted: Tue Aug 24, 2004 8:49 pm
by feyd

Code: Select all

if (isset($_SESSION['frm_username']))
   {   
      showPage();
   }
   else
   {
      header("Location:login.php");
   }

maybe it's hitting this before it can remove the data? What happens if you force refresh the page after you hit the remove link?

Posted: Tue Aug 24, 2004 9:01 pm
by dardsemail
If I refresh it, the data is gone - so its clearly working. I just can't figure out how to run this so it works... I can't seem to get the ordering right.

Posted: Tue Aug 24, 2004 9:04 pm
by feyd
run the quoted code as the default case of the switch on action...

Posted: Wed Aug 25, 2004 9:38 am
by dardsemail
I changed the switch section to be the following and its still not working:

Code: Select all

<?php
switch(@$_GET["action"]) 

	{
		case "remove_orders":
		{
			RemoveOrder($_GET["orderID"]);
		}
		default:
		{
			showPage();
			}
	}

?>
Is that what you had meant? I wasn't sure where to place it.

Posted: Wed Aug 25, 2004 9:43 am
by malcolmboston
just putting another solution across....

Could it be a browser caching problem??

Posted: Wed Aug 25, 2004 11:34 am
by dardsemail
I don't think its a caching problem. I actually copied the code from another application I have that works properly. Here is the code from which it was copied:

Code: Select all

<?php
switch(@$_GET["action"]) 

	{
		case "remove_item":
		{
			RemoveItem($_GET["piecenum"]);
			break;
		}
	}

	function RemoveItem($piecenum)
	{
		// Uses an SQL delete statement to remove an item from
		// the users cart

		include ('connection/db.php');
				
		mysql_query("DELETE FROM cart WHERE cookieId = '" . GetCartId() . "' AND piecenum = $piecenum");
	}

?>
This code doesn't require that I click twice. Very strange...

Posted: Wed Aug 25, 2004 11:39 am
by markl999
if (isset($_SESSION['frm_username']))
{
showPage();
}
else
{
header("Location:login.php");
}
Try moving that code below your switch() statement. The problem looks like you are first displaying the page then doing the delete, rather than doing the delete then displaying the page.

Posted: Wed Aug 25, 2004 11:44 am
by dardsemail
That's the ticket! Thanks so much!!!!