Hi,
I currently have an issue with a shopping cart script I am using. I am using a MySQL database to store product information and to hold the values of the shoppng cart.
The shopping cart script uses a switch($_GET["action"]) statement to get the action sent to it, e.g.
<?php
include("db.php");
switch($GET["action"])
{
case "add_item":
{
AddItem($GET["id"], $GET["qty"], $GET["sign"]);
ShowCart();
break;
}
case "update_item":
{
UpdateItem($GET["id"], $GET["qty"]);
ShowCart();
break;
}
case "remove_item":
{
RemoveItem($_GET["id"]);
ShowCart();
break;
}
default:
{
ShowCart();
}
}
The problem I have is, it seems to matter where I store this script, and rest of the pages of the website, as to whether the script works.
What I mean by this is it works fine if I upload all pages and scripts to:
but if I upload all my scripts and pages to.....:
http://www.mywebsite.com/shoppingpages/
......it will not will not insert the product chosen by the visitor in to the shopping cart.
By uploading all my scripts and pages to the Shoppingpages directory within my site, the rest of the scripts work perfectly, e.g. connecting to the database, displaying the right product from the database when chosen by the visitor etc.... but just not to add a product to the database.
An example of the URL given to the shopping cart script from the product page (when a product is chosen to be added to the shopping cart) is:
cartbooks.php?action=add_item&id=1&qty=1&sign=3
and in the shopping cart scripts Add_Item funtion looks like this:
function AddItem($itemId, $qty, $sign)
{
global $dbServer, $dbUser, $dbPass, $dbName;
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$result = mysql_query("select count(*) from cart1 where cookieId = '" . GetCartId() . "' and itemId = $itemId");
$row = mysql_fetch_row($result);
$numRows = $row[0];
if($numRows == 0)
{
@("insert into cart1(cookieId, itemId, qty, sign) values('" . GetCartId() . "', $itemId, $qty, $sign)");
}
else
{
UpdateItem($itemId, $qty);
}
}
Does anyone know as to why the the shopping cart and Add_Item function only seems to work by uploading to:
as opposed to:
http://www.mywebsite.com/shoppingpages/
????
Many thanks,
Dean