Jump to content

Passing Values From Js To Php


Interista

Recommended Posts

And I want to keep the cart info even if someone refresh the page .

 

Then you should store the cart info in the database or in SESSION data. But, to answer your question directly you can pass variables from the client to the server using Javascript by performing an AJAX request - which I wouldn't suggest for cart info.

Link to comment
Share on other sites

Then you should store the cart info in the database or in SESSION data. But, to answer your question directly you can pass variables from the client to the server using Javascript by performing an AJAX request - which I wouldn't suggest for cart info.

Hello ,

I think it's not good to store the cart info in a database ! so much quires .

is that bad in PHP have much quires ?

 

Thank u :)

Link to comment
Share on other sites

Hello ,

I think it's not good to store the cart info in a database ! so much quires .

is that bad in PHP have much quires ?

 

That question cannot be answered. The appropriate number of "queries" (or what I think you mean is how much data should be stored) is completely dependent upon the needs of the application. If the needs of the application requires 5 queries or 500 queries then that is what it takes.

 

To address your specific need, you are wanting to store a user's cart. There are a few different solutions and which one you choose can depend on many factors.

 

You can use sessions, but they will only persist for the user's session (obviously). This is pretty easy to manager.

 

You can store the info in cookies, which will persist across sessions. But, if a user saves a cart it would only be available to them on that same pc.

 

If you want carts to persist across sessions and PCs then you will want to store them in the DB and ties to a user login.

 

There is no right or wrong method - it depends on which one meets your specific needs. Many sites use several methods.

Link to comment
Share on other sites

That question cannot be answered. The appropriate number of "queries" (or what I think you mean is how much data should be stored) is completely dependent upon the needs of the application. If the needs of the application requires 5 queries or 500 queries then that is what it takes.

 

To address your specific need, you are wanting to store a user's cart. There are a few different solutions and which one you choose can depend on many factors.

 

You can use sessions, but they will only persist for the user's session (obviously). This is pretty easy to manager.

 

You can store the info in cookies, which will persist across sessions. But, if a user saves a cart it would only be available to them on that same pc.

 

If you want carts to persist across sessions and PCs then you will want to store them in the DB and ties to a user login.

 

There is no right or wrong method - it depends on which one meets your specific needs. Many sites use several methods.

Oh OK , great info that will help me for sure .

Thanks for help :)

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.