Re: Loops

From: Date: Thu, 17 Aug 2000 01:50:41 +0000
Subject: Re: Loops
References: 1  Groups: php.windows 
Request: Send a blank email to php-windows+get-1874@lists.php.net to get a copy of this message
Hmmm... I'm new too, but will try to answer. If I make mistakes I would appreciate correction from those that really know... > 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"); This is probably not the best way, you could probably use (line truncated, but it is all one command): header("Location: http://your.site.com/TellAFriend.php?Name=\"$Name\"&...other vars"); Just use the "header" function before any other output, otherwise it won't redirect your browser. This way you call again the "TellAFriend.php" instead of "including" it form TellAFriendSubmit. That is, you finish with TellAFriendSubmit and call TellAFriend again. Since HTML is stateless, if you want to pass values from one page to another you must specify them somehow, usually via the URL. So, to reload TellAFriend.php with the values received by TellAFriendSubmit.php you must place them in the URL for TellAFriend to receive them (as I presented them in the "header" example). <snip> > 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? No stacks, no loops, no consumed resources, HTML is stateless. It doesn't remember you from one "GET" to another. > 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? That's the "header" function with the variables in the URL. Just remember: it _must_ be the first output of your script. (Don't worry, if it's not, PHP will happily remind you). > 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. This is solved because the script being run is TellAFriend itself, not included in TellAFriendSubmit. > 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? You can have both in one script, but I'd rather use two separate scripts. Depends on your way of coding... > 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 ;) Well, if you send me your scripts I'll gladly help you work them out. Since I'm learning too, this will be a good excercise, a little off my actual developing. Gonzalo.

« previous php.windows (#1874) next »