Page 1 of 2
Code works beautifully on my iMac, but not so well online
Posted: Thu Jun 03, 2004 9:02 pm
by dardsemail
I'm having a bit of a problem and I'm not sure what to do. I've written some code (of which I'd be happy to post if it would be helpful) for a shopping cart application. When I run it through the test server on my iMac it works beautifully - both smooth and fast. No problems at all.
When I upload it to my hosting providers servers, it craps out on me. It inconsistently adds the items to the shopping cart and often shows an empty cart when I know there are items in there. Hitting refresh several times will sometimes bring the cart back. Its very frustrating and I'm wondering if a difference in PHP/mySQL versions between my machine and their servers will cause this to happen or whether there are any other possible causes. Bottom line, its preventing me from launching the site for my client and I'm stuck!
Help!!!
Posted: Thu Jun 03, 2004 10:48 pm
by feyd
is the page(s) using frames/iframes? Do each of these frames, set a cookie (for session, or something)? I've had problems with browsers getting royally confused about which cookie it's working on, and the server thinking a different cookie is the (real) one.
Posted: Fri Jun 04, 2004 8:00 am
by dardsemail
No, its not using frames. I can't figure it out and its very frustrating as its a roadblock to us launching our site.
It is, however, using cookies to idenitfy the session. Any thoughts?
Posted: Fri Jun 04, 2004 1:02 pm
by launchcode
Are you running the same versions of PHP on the Mac and server? How differently are they configured? (register globals, error handling, etc)
Posted: Fri Jun 04, 2004 2:11 pm
by leenoble_uk
This is probably redundant but something you might want to bear in mind.
What are you using to write the scripts? BBEdit?
If you're not using BBEdit, use BBEdit or perhaps Hydra (I forget its new name).
Whichever you use make sure it is set to UNIX style line endings. The Macintosh line endings may work on your computer but on a server things could get funky or not work at all.
What program do you use to upload to the server? Transmit?
Something which caught me out for a while with Transmit is again related to line endings. You must open the preferences and set .php files to upload as ASCII files. I think this is default now but it wasn't in the past so it depends how old your copy is.
These are probably unlikely since you are getting something working but it doesn't hurt to know now does it. It's more likely to be that you're running a different version of PHP or MYSQL or both.
Use the phpinfo() function on your iMac and on the server to see the php differences. It could even be something which was left out of the compile when php was installed.
Posted: Sat Jun 05, 2004 5:35 am
by dardsemail
I've been using Dreamweaver MX 2004 for development and have selected a company that hosts on Mac hardware hoping to avoid this kind of inconsistency.
I'll check though...
Posted: Sat Jun 05, 2004 4:34 pm
by dardsemail
I did a phpinfo() on both my machine and the server that the site is running on - but I'm not sure what the differences in configuration I'm looking for are.
Also, regarding the line wraps - how would I be able to tell what kind of line wraps I'm using? I'm pretty novice at this and I'm truly baffled.
Thanks!
Posted: Sat Jun 05, 2004 5:56 pm
by markl999
What version of PHP are both using and what's the value of register_globals on them both ?
Posted: Sat Jun 05, 2004 10:26 pm
by dardsemail
My iMac is using 4.3.2/register_globals OFF
The web server is using 4.2.3/register_globals ON
Obviously both are different. What can I do about this? I'm not sure I can get my hosting company to change their settings? Can I change my code to make this work or what other options do I have?
Thanks so much for your help!!!! Its very much appreciated!
Posted: Sat Jun 05, 2004 10:31 pm
by markl999
Well, to see if it's the register_globals difference first you can create a .htaccess file on put it in the root dir of your website (on the server).
In the .htaccess put:
php_value register_globals 0
Reload your phpinfo() page to make sure that the change has taken effect (it shoud now say OFF).
If it does say OFF and there's no change in the code crapping out, the it could easily be down to the version of PHP, i'd bug your host to upgrade to at least 4.3.2 (though 4.3.7 is now the stable release).
Posted: Sun Jun 06, 2004 8:10 am
by dardsemail
Okay, I'm definitely new to all of this - so, I hate to be a pest - but could you walk me through how I create an .htaccess file? I'm sorry, but I'm really not sure how to do it.
Thanks so much! I really appreciate your help!
Cheers,
Darlene
Posted: Sun Jun 06, 2004 8:38 am
by launchcode
It's just a plain text file - put the text mark suggested into it, give it the same name (the period/fullstop at the start is vital) and upload it. Then hope your host supports them
To be honest most of the time you get problems going from a register globals ON to an OFF environment - but you're doing the reverse, so it shouldn't be much of an issue for you. Is there part of your script (ideally a real short one) you could post here for us to see?
Posted: Sun Jun 06, 2004 9:19 am
by dardsemail
I think I did something wrong.
1) I created a file called '.htaccess'
2) In this file was the following line (and nothing else):
php_value register_globals 0
3) I uploaded this to the web server and put it in the root folder and it didn't work.
This is the error I got:
'Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Apache/1.3.27 Server at xxx Port 80'
What am I doing wrong?
Thanks!
Posted: Sun Jun 06, 2004 10:11 am
by dardsemail
launchcode wrote:It's just a plain text file - put the text mark suggested into it, give it the same name (the period/fullstop at the start is vital) and upload it. Then hope your host supports them
To be honest most of the time you get problems going from a register globals ON to an OFF environment - but you're doing the reverse, so it shouldn't be much of an issue for you. Is there part of your script (ideally a real short one) you could post here for us to see?
I've listed the code below...
Code: Select all
<?php
include("include.php");
switch($_GETї"action"])
{
case "add_item":
{
AddItem($_GETї"piecenum"], $_GETї"qty"]);
ShowCart($rs_cart);
break;
}
case "update_item":
{
UpdateItem($_GETї"piecenum"], $_GETї"qty"]);
ShowCart($rs_cart);
break;
}
case "remove_item":
{
RemoveItem($_GETї"piecenum"]);
ShowCart($rs_cart);
break;
}
default:
{
ShowCart($rs_cart);
}
}
function AddItem($piecenum, $qty)
{
// Will check whether or not this item
// already exists in the cart table.
// If it does, the UpdateItem function
// will be called instead
// Get a connection to the database
// Check if this item already exists in the users cart table
$result = mysql_query("SELECT count(*) FROM cart WHERE cookieId = '" . GetCartId() . "' AND piecenum = $piecenum");
$row = mysql_fetch_row($result);
$numRows = $rowї0];
if($numRows == 0)
{
// This item doesn't exist in the users cart,
// we will add it with an insert query
@mysql_query("INSERT INTO cart(cookieId, piecenum, qty) VALUES('" . GetCartId() . "', $piecenum, $qty)");
}
else
{
// This item already exists in the users cart,
// we will update it instead
UpdateItem($piecenum, $qty);
}
}
function UpdateItem($piecenum, $qty)
{
// Updates the quantity of an item in the users cart.
// If the qutnaity is zero, then RemoveItem will be
// called instead
if($qty == 0)
{
// Remove the item from the users cart
RemoveItem($piecenum);
}
else
{
mysql_query("UPDATE cart SET qty = $qty WHERE cookieId = '" . GetCartId() . "' AND piecenum = $piecenum");
}
}
function RemoveItem($piecenum)
{
// Uses an SQL delete statement to remove an item from
// the users cart
mysql_query("DELETE FROM cart WHERE cookieId = '" . GetCartId() . "' AND piecenum = $piecenum");
}
function ShowCart()
{
// Gets each item from the cart table and display them in
// a tabulated format, as well as a final total for the cart
// Get a connection to the database
$totalCost = 0;
$result = mysql_query("SELECT * FROM cart INNER JOIN pieces ON cart.piecenum=pieces.piecenum WHERE cookieID='" . GetCartId() . "'");
?>
<title> Your Shopping Cart </title>
<script language="JavaScript">
function UpdateQty(item)
{
itemId = item.name;
newQty = item.optionsїitem.selectedIndex].text;
document.location.href = 'cart.php?action=update_item&piecenum='+itemId+'&qty='+newQty;
}
</script>
Posted: Sun Jun 06, 2004 7:26 pm
by launchcode
There is nothing fundamentally wrong with any of the code you posted, so I'd have to start looking elsewhere - specifically the cookie handling (which you appear to be using) - where are these values set/retrieved?