0

I have a PHP file that contains a button. When the button is clicked an external PHP file is loaded into a div on the same page. The external PHP file contains a form with a hidden variable, the values is set to a PHP variable that was defined in the page with button.

Since the PHP file is loaded into the page's div shouldn't it have the same variables as the page?

1
  • 1
    The php script is server side. The html is client side. The two are completely separate even if you put them both in the same file. html can't access the php script variables. However, you can display the output of a php script inside html tags and that can create confusion. The php script on the page with the button would have to take in the external variable and define it before displaying the value in the html tags in your case. Commented Aug 30, 2010 at 21:52

1 Answer 1

1

HTTP is stateless. There's no inherent connection between one request and another, even if they were both requested at the same time. The variables used in a page normally get tossed out when the request is done, and simply aren't there for the next request.

If you want to carry a variable over from one PHP script to another, you'll need to either put it in $_SESSION, use cookies, or pass the variable in the query string when you request the contents for your div.

Sign up to request clarification or add additional context in comments.

1 Comment

Got it, thanks for clearing that up. I guess I'll change it to a session variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.