Loops
| From: | James Duncan | Date: | Thu, 17 Aug 2000 00:29:48 +0000 |
| Subject: | Loops | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-1869@lists.php.net to get a copy of this message | ||
Hi folks,
I'm very new to PHP, HTML and programming in general. I'm running Apache,
MySQL and PHP4 on Windows 2000. This is probably a very stupid question but
I just want to make sure that what I'm doing won't cause any problems.
From "InviteAFriend.php" I gather user input via an HTML form and when the
user hits the "Submit" button it calls (POST) another PHP file
"InviteAFriendSubmit.php". This performs data validation and if all is
correct sends the email and displays a confirmation message to the user.
However, if the inputted data is invalid I redisplay the "InviteAFriend.php"
file by:
include ("TellAFriend.php");
The "TellAFriend.php" file includes PHP variables that are set by
"InviteAFriendSubmit.php". For example:
<?php
print "<p style=\"margin-top: 0\"><font face=\"Verdana\"
size=\"1\"><input
type=\"text\" name=\"Name\" size=\"20\"
value=\"$Name\"><font
color=\"#FF0000\"> $ErrorName";
?>
My reasons for doing this are as follows. When "TellAFriend.php" is first
run all variables are blank and therefore the form is displayed with all
text boxes empty and no error messages being displayed. The user fills out
the form and hits "Submit". This runs "TellAFriendSubmit.php", which does
its thing. If it finds any errors it inserts relevant comments into the
variables ($ErrorName = "Invalid name entered"). Then it redisplays
"TellAFriend.php" and this time the variables contain values, which are
displayed to the user. As you can see from the above code I get PHP to
insert the user input back into the textboxes when "TellAFriend.php" is
redisplayed so that the user doesn't need to re-input it.
Now for my questions. I have obviously set up a loop because if errors are
detected "TellAFriendSubmit.php" redisplays "TellAFriend.php". This will
continue until either the user cancels the operation or correctly fills out
the form. Does PHP release all resources every time "TellAFriendSubmit.php"
ends? By doing this am I filling up a stack or something like that?
Is it possible that if errors are found that I can get PHP to display
"TellAFriend.php" again rather than use the include command but for the
variable contents to be maintained? For example, when the user first arrives
they see "TellAFriend.php" in the URL address box on their browser. When
they hit submit they see "TellAFriendSubmit.php" and even when it redisplays
the "TellAFriend.php" file it still says "TellAFriendSubmit.php" in the URL
address. This is a really minor point but I would prefer it to revert back
to the original name in the URL address if possible.
Do I need to have two separate PHP files? Is it possible that when the user
hits Submit instead of calling another file it could call PHP functions in
the same file to do the processing? Is it necessary to call another file
when you POST data before you can access the variables declared in the form?
Sorry for these rather basic/stupid questions but I want to make sure I'm
heading in the right direction. Please keep all coding examples simple or
well documented ;)
Many thanks for your help in advance
James