Reply to Re: header() with if/then statements

Your name:

Reply:


Posted by Jerim79 on 11/17/06 21:15

Jerim79 wrote:
> e_matt...@hotmail.com wrote:
> > > Here is the basic gist of what I have:
> > >
> > > <?php
> > > $FName=$_Post['FName'];
> > >
> > > if ($FName !=""){
> > > header("Location: write_to_database.php");
> > > }
> > > else{
> > > if ($FName=""){
> > > $errormsg1="Please enter a first name":
> > > }
> > > ?>
> > >
> > > <html>
> > > <body>
> > > Registration
> > > <?php if ($errormsg1 !="") echo $errormsg1); ?>
> > > <br />
> > > <form action="(this page)"
> method="Post">
> > > First Name: <input type="text" name="FName">
> > > <br />
> > > <input type="submit" name="submit value="Submit">
> > > </form>
> > > </body>
> > > </html>
> > >
> > > Forgetting the problem about loading the errors up before filling out
> > > the form, I can't get this to work at all. After I click on submit it
> > > just brings me back to the same page, with no error messages.
> >
> > Try:
> > <?php
> >
> > $FName = "";
> > $errorMsg1 = "";
> >
> > if ($_POST) {
> >
> > if ( isset($_POST['FName']) ) {
> > $FName = $_POST['FName'];
> > }
> >
> > Now you can validate $FName, because it's either empty or set to
> > user's value. Don't write to database without validating all data.
> > The rest looks good. Good luck.
>
> Since I am still learning, I just wanted state the logic of the code.
> First we set $FName equal to nothing. Then we set $errorMsg1 equal to
> nothing. Next we say "if the method is $_POST" then check to see if
> $_POST['FName'] has been set. If it has, then set $FName equal to
> $_POST['FName']
>
> I still can't get it to display the error message.

Here is the current, non-working code:

<?php
$FName="";
$errormsg1="";

if( isset($_POST['FName']){
$FName=$_POST['FName'];
}

if ($FName !=""){
header("Location: write_to_database.php");
}
else{
if ($FName=""){
$errormsg1="Please enter a first name":
}
?>
<html>
<body>
Registration
<?php if ($errormsg1 !=""){ echo $errormsg1; } ?>
<form action="new.htm" method="POST">
First Name: <input type="text" name="FName">
<br />
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация