The accepted (most flexible / least troublesome) way to develop shopping carts is using sessions to store the browsers cart data.
This means that you use a cookie / passed GET variable to identify a user and retrieve their data from a database.
PHP4 - see session management functions
PHP3 - try PHPLIB / write your own.
Good luck
Matt B