Page 1 of 1

executing process of php file

Posted: Mon Jul 25, 2005 9:12 am
by php12342005
as I know (not sure), a php file is always re-executed from first line to last line after user presses a submit button - is this right?

for example, I add following code in a php file:

<?php
if(isset($_POST['form_Submit']))
{
//something
}
?>
//more html code here which includes a form with submit button.

if user presses submit button, the file will be re-executed from first line to last line, right?

If right, it causes a big visual problem: the file will be re-loaded again and whole page twinkles - bad visual performace.

how to avoid the problem?

thanks

Posted: Mon Jul 25, 2005 9:44 am
by pickle
When submitting a form, you are POSTing the data to another page. So, you are moving from the current page to that new page (which, could actually be the curent page - confused?). The "twinkle" you see is the page loading again.

While it would be bad performance for an executable program - PHP build web applications, so going from one page to another is to be expected.

An alternative might be XMLhttp - lets you send and receive data without reloading a page. ~Burrito knows quite a bit.

Posted: Mon Jul 25, 2005 12:31 pm
by php12342005
why must the file open a new file?
It can use current file - I do in this way.

Posted: Mon Jul 25, 2005 12:55 pm
by pickle
That's often done - submiting a form to the current page. However, that won't remove the flicker you see.

The way PHP, webservers and the Internet work is through stateless connections. When you submit your form to the current document, you're actually asking the webserver to send you another copy of the document. So, there will be a flicker (or possible a longer wait) regardless of the page you submit your form data to.