tags:

views:

28

answers:

2

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?

A: 

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.

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

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