Re: form to php
| From: | Al Jones | Date: | Fri, 30 Jul 2004 04:19:50 +0000 |
| Subject: | Re: form to php | ||
| References: | 1 2 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-24292@lists.php.net to get a copy of this message | ||
Very nice answer Mark, some of us newbies get lost in the fray here so *I*
really appreciate when someone takes the time to show how and explain the
workings. I'm tackling a form and database, and as a new php person it's a
bit intimidating!
"Mark Collin" <mark@ardescosolutions.co.uk> wrote in message
news:20040729184458.83876.qmail@pb1.pair.com...
> You haven't closed your form tag which is causing it to all go wrong.
>
> Here is some working code for you:
>
> <form action="action.php" method="post">
> <p>Your name: <input type="text" name="name"></p>
> <p>Your age: <input type="text" name="age"></p>
> <p><input type="submit" /></p>
> </form>
> action.php:
> <?php
> //Check to see if user has clicked submit
> if (isset($_POST['name']) && isset($_POST['age']))
> {
> //Check to see if user has entered data in both fields
> if (!empty($_POST['name']) && !empty($_POST['age']))
> {
> //User has entered data in both fields so display result
> ?>
> Hi <?php echo $_POST['name']; ?> .You are <?php echo
> $_POST['age'];
> }
> else
> {
> //User has not populated both fields so send a warning to user telling
> them what to do
> ?>
> <script language="javascript" type="text/javascript">
> window.alert('You must complete both fields');
> </script>
> <?php
> }
> }
> ?>
>
> You would probably find it easier to read if you format your HTML a
> little, a little formatting goes a long way when it comes to debugging
> HTML, especially if your using the devils own tables :P
>
> "Php mysql" <dailymails4me@yahoo.co.in> wrote in message
> news:20040729082358.48834.qmail@web8306.mail.in.yahoo.com:
> > hi list,
> >
> > i have managed to successfully install php and i am now going through
> > the manual and trying a few of the examples given there. The examples
i have
> > tried till now are all working except for one. The example about
inputting
> > in the form and then displaying it through php is not working for me.
But
> > when i run it i get the entire code in action.php instead.
> > The example i am referring to is:
> >
> > form action="action.php" method="post"> <p>Your name:
> > <input type="text"
> > name="name" /></p> <p>Your age: <input type="text"
> > name="age" /></p>
> > <p><input type="submit" /></p></form
> >
> > action.php:
> >
> > Hi <?php echo $_POST['name']; ?>.You are <?php echo
> > $_POST['age']; ?>
> >
> >
> >
> > Please tell me whts wrong....
> >
> > thanks in advance
> >
> > penjo
> >
> > Yahoo! India Matrimony: Find your life partneronline.