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:

http://www.mywebsite.com/

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:

http://www.mywebsite.com

as opposed to:

http://www.mywebsite.com/shoppingpages/

????

Many thanks,
Dean

    My tired eyes couldn't spot the problem in your code if there is one... I did notice that you are using an include() line. You may want to consider using an absolute path instead of a relative path. The probably explains at least why your script isn't working elsewhere in your directory tree.

      Hi Rachel,

      I appreciate the response and did amend the include() statement to an absolute URL, but unfortunately now the shopping cart screen remains completely blank page - no errors, no images, no text etc....

      By keeping the include() statement link relative it does display the page but shows a blank shopping cart, and checking the database, no entries are updated.

      It sure is giving me a headache !!

      The rest of the pages and PHP scripts seem to be able to deal with the relative link within the include() statement.

      Really hoping that someone knows the solution!

      Thanks,
      Dean

        I don't think it's the include but why don't you try placing error_report(E_ALL) at the top of your script and then seeing if there is any errors on the input.

          Hi Drawmack,

          Thanks for the reply......

          I placed that code in the top of the script (handy piece of code, I was not aware of that - thank you!)

          I now have an error message that reads the below:

          Warning: Undefined variable: _GET in /home/.sites/97/site139/web/bookshop/cartbooks.php on line 7

          Line 7 of the shopping cart script (cartbooks.php) reads the Switch command:

          switch($_GET["action"])

          Does this help?

          Thanks,
          Dean

            Hi,

            Having tested this again I have now discovered this script does not work on either:

            http://www.mywebsite.com

            or

            http://www.mywebsite.com/shoppingpages/

            but it does work on:

            http://www.myotherwebsite.com

            and

            http://www.myotherwebsite.com/shoppingpages/

            (both websites are hosted with the same web hosts)

            Is it possible that the two websites have different PHP versions set up on the hosts servers and this is what is causing the error?

            If so, is there a different version of the switch($_GET["action"]) variable that may need to be used?

            Many thanks,
            Dean

              Write a Reply...