Jump to content

Help with direction to take


Recommended Posts

I want to create a shopping cart system for my website, but a simple shopping cart. I don't want a registration form or anything like that, just a way to add or delete a product..... so, how am I going to achieve this? I don't know! I don't know what I am even suppose to be looking for. Though, I do suspect I need to learn something called "PHP sessions" to store a cookie on someones computer to keep the shopping cart active.

 

I use MySQL for my database, so I am guessing I will need to also create some form of temporary storage table as well.

To be honest, I am shitting myself and have feared this task for over a month, but I am brave and going to take the plunge. In my head I can picture the process actually being very simple: a cookie is stored on someones computer > adding to cart simply is a HTML form that PHP then adds to MySQL > on purchase PHP calls the data from MySQL and forwards it to the payment gateway API.

... but I am only asking for advice on the PHP session and storing the cart in MySQL... The payment API will be a simple matter of PHP pulling information from MySQL and forwarding it to the API.

 

Can someone please point me to the right.... concept... or something?

Link to comment
Share on other sites

Are you saying you won't be taking any user information?  Seems like you'd need to have user create an account and add credit info to process the order.  Creating a place to enter product info and and displaying isn't hard.  User selection of item and setting this to session is also easy.  Start with creating DB table to hold product information.  IF you're just learning this I would add some values to the DB table and work on querying the DB to display products.  Really, adding a login system would then allow you to identify yourself as the "admin" user and based on this, have links to add products and view orders etc.  I guess it depend on what you're trying to do.

Link to comment
Share on other sites

Are you saying you won't be taking any user information?

Nah, information will be collected.. that will come at payment time.... thats another process that has nothing to do with the cart.. I've got it sorted.

 

User selection of item and setting this to session is also easy.

 

I think this is what I am after.

 

Start with creating DB table to hold product information.

Already done.

Link to comment
Share on other sites

PHP sessions can and do facilitate this. Sessions by default are actually small files that are stored on the server.  An associated cookie for the session id is sent to the client and that is how the server knows on subsequent requests that the same browser is making a new request.  Unlike cookies, the good thing about this is that the data in the session stays on the server.

 

You could put the cart data into a database but practically speaking it is not necessary until the point you actually have an order.  The choice is really yours.

 

The basics of sessions are very simple.  On every page that uses sessions you must start the session first.  Most people have an initialization/include of this function:

 

 

session_start();

 

Now you can read session variables that have been set, change them or add new ones, using the $_SESSION superglobal.

 

 

$_SESSION['items']++;
echo "You have {$_SESSION['items']} in your cart now.";

 

Try this on a page and as you refresh it you will see the count increase if you've done everything normally.  That should be enough to get you started, but I'd recommend reading the http://us3.php.net/manual/en/book.session.php even if you don't completely understand everything in it.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.