i have a variable $cartTotal in cart.php page i want to use that same $cartTotal in another page and want to insert value of $cartTotal in table
how to do this
?
thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are a few ways to give a variable to anothe page, i think you don’t use any frameworks, so I’ll explain just the basic ways:
At first, start a Session. At the very first of your script, add this:
There must not be any other code before this, not even whitespace.
So now, you can set Session-Variables like this:
The Variable $_SESSION[‘cartTotal’] will now be available on every page, you can use it just like a normal variable.
The second facility is, to give a variable to another page by it’s link with the GET-Method. E.G. set up your link like this:
The Variable will be available in $_GET[‘cartTutorial’] but only in the next page and just by clicking this link. Also the GET-Method ist just good for simple variables, only text and numbers for example, arrays cannot be set.
Third possibility is the POST-Method, but it just works with a form and is just interesting if you are using one.
Simpliest possibility in my opinion is to make a session-variable.