executing process of php file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php12342005
Forum Commoner
Posts: 79
Joined: Mon Mar 21, 2005 3:35 am

executing process of php file

Post 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
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
php12342005
Forum Commoner
Posts: 79
Joined: Mon Mar 21, 2005 3:35 am

Post by php12342005 »

why must the file open a new file?
It can use current file - I do in this way.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply