custom script help

I’m trying to make the update qty script for our cart work so it stays on the page you are on, eg, if the qty is changed at stage 3 of the cart the qty updates & you stay on cart 3. Currently it would take you back to cart stage 1!

The code currently looks like this :-

[php]<?php
session_start();
if ( $_SESSION[‘locked’] != 1 )
{
include_once(“config.php”);
if ( ( !isset($_POST[‘cartitem’]) ) || ( $_POST[‘cartitem’] == ‘’ ) )
{
include_once(“top.php”);
echo ‘Please go back and select a product to change the quantity of from your cart.’;
include_once(“bottom.php”);
}
else
{
if ( $_POST[‘quantity’] == ‘0’ )
{
$sql = “UPDATE cartitems SET active=‘0’ WHERE cartitemid=’”.mysql_real_escape_string($_POST[‘cartitem’])."’";
mysql_query($sql);
}
else
{
$sql = “UPDATE cartitems SET quantity=’”.$_POST[‘quantity’]."’ WHERE cartitemid=’".mysql_real_escape_string($_POST[‘cartitem’])."’";
mysql_query($sql);
}
header (“Location: cart.php”);
}
}
else
{
header (“Location: cart.php”);
}
?>[/php]

I tried modifying the link on each cart page so rather than the script called as I changed it to for cart1.php then cartpage=b for cart2.php etc. I then modified the script attached as follows :-

[php]include_once(“bottom.php”);
}
else
{
if ( $_POST[‘quantity’] == ‘0’ )
{
$sql = “UPDATE cartitems SET active=‘0’ WHERE cartitemid=’”.mysql_real_escape_string($_POST[‘cartitem’])."’";
mysql_query($sql);
}
else
{
$sql = “UPDATE cartitems SET quantity=’”.$_POST[‘quantity’]."’ WHERE cartitemid=’".mysql_real_escape_string($_POST[‘cartitem’])."’";
mysql_query($sql);
}
header (“Location: cart.php”);
}
}
else
{
if ( $_GET[‘cartpage’] == “a” )
{
header (“Location: cart.php”);
}
if ( $_GET[‘cartpage’] == “b” )
{
header (“Location: cart2.php”);
}
if ( $_GET[‘cartpage’] == “c” )
{
header (“Location: cart3.php”);
}
}
?>[/php]

But it didn’t work, can anyone suggest how I can get this to work. I know nothing about PHP so i’m just trying my best here.

Thanks for any help anyone can offer :slight_smile:

Well, normally, this process would be handled by just saving the current cart in a variable.

You did it sort of… You showed us how you passed the values and how you decode the value.
(I might have just passed the cart number and did one header command instead of all that testing!)

But, you did not show us where this was called from. If you have three pages named
cart.php, cart2.php and cart3.php, you call these from somewhere, correct? Also, if you have
three differrent carts is the code inside each of them unique or basically the same?

Why do you need three carts? I mean, normally a cart is a cart and there are not three of them.
Are the carts stored inside a database? Couldn’t you just use a field to designate them there and
when the one cart file is loaded it would check that field and display as needed?

Not sure why or what you are asking help on. You can use header to post to a form using a get arg,
and the page that is called would need to check the arg BEFORE it does anything else.

Please give us a better idea of the process you are trying to solve…

Sponsor our Newsletter | Privacy Policy | Terms of Service