Transferring variables from form to php

This is a discussion on Transferring variables from form to php within the PHP General forums, part of the PHP Programming Forums category; I'm trying to pass data from an HTML form to PHP. Later, I'll write the data to a ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-10-2004
L.Ray
 
Posts: n/a
Default Transferring variables from form to php

I'm trying to pass data from an HTML form to PHP. Later, I'll write the
data to a database. Please look at this simple html form, php code,
and the output and tell me what I'm doing wrong. Thanks in advance:


<!-- Sample.html -->
<html>
<body>

<form action="simple.php" method="POST" >
Name: <input type="text" name="wName" size="20"><br>
Email: <input type="text" name="wEmail" size="20"><br>
<input type="submit" value="submit" name="submit">
</form>

</body>
</html>

<!-- simple.php -->
<HTML>
<body>
<?php
if (!$wName || !$wEmail )
{
echo "You have not entered all the required details.<br>"
."Please go back and enter data in all fields.<br>";
echo ".$wName., .$wEmail.";
exit;
}
?>
</body>
</HTML>

<!-- here is the output from the above code -->

You have not entered all the required details.
Please go back and enter data in all fields.
..., ..
Reply With Quote
  #2 (permalink)  
Old 05-14-2004
DrTebi
 
Posts: n/a
Default Re: Transferring variables from form to php

On Sat, 10 Jan 2004 13:33:31 -0800, L.Ray wrote:

> I'm trying to pass data from an HTML form to PHP. Later, I'll write the
> data to a database. Please look at this simple html form, php code,
> and the output and tell me what I'm doing wrong. Thanks in advance:
>
>
> <!-- Sample.html -->
> <html>
> <body>
>
> <form action="simple.php" method="POST" >
> Name: <input type="text" name="wName" size="20"><br>
> Email: <input type="text" name="wEmail" size="20"><br>
> <input type="submit" value="submit" name="submit">
> </form>
>
> </body>
> </html>
>
> <!-- simple.php -->
> <HTML>
> <body>
> <?php
> if (!$wName || !$wEmail )
> {
> echo "You have not entered all the required details.<br>"
> ."Please go back and enter data in all fields.<br>";
> echo ".$wName., .$wEmail.";
> exit;
> }
> ?>
> </body>
> </HTML>
>
> <!-- here is the output from the above code -->
>
> You have not entered all the required details.
> Please go back and enter data in all fields.
> .., ..


I suppose you entered a Name and Email in sample.html, send it off, and
then got the error...
The problem is probably that your server has "register_globals" set to
"Off", which all new PHP distributions have. That means the $wName and
$wEmail variables are not available for the simple.php script. You will
have to use the $_POST variables to get them.
To fix this problem, just replace $wName and $wEmail with $_POST['wName']
and $_POST['wEmail'].

DrTebi
Reply With Quote
  #3 (permalink)  
Old 05-16-2004
Virtual_Odin
 
Posts: n/a
Default Re: Transferring variables from form to php

There is a small mistake in your code

The line echo ".$wName., .$wEmail.";

should be echo $wName.", ".$wEmail";

See if that helps...

Yours, Tim

DrTebi <DrTebi@yahoo.com> wrote in message news:<pan.2004.05.14.12.16.00.143000@yahoo.com>...
> On Sat, 10 Jan 2004 13:33:31 -0800, L.Ray wrote:
>
> > I'm trying to pass data from an HTML form to PHP. Later, I'll write the
> > data to a database. Please look at this simple html form, php code,
> > and the output and tell me what I'm doing wrong. Thanks in advance:
> >
> >
> > <!-- Sample.html -->
> > <html>
> > <body>
> >
> > <form action="simple.php" method="POST" >
> > Name: <input type="text" name="wName" size="20"><br>
> > Email: <input type="text" name="wEmail" size="20"><br>
> > <input type="submit" value="submit" name="submit">
> > </form>
> >
> > </body>
> > </html>
> >
> > <!-- simple.php -->
> > <HTML>
> > <body>
> > <?php
> > if (!$wName || !$wEmail )
> > {
> > echo "You have not entered all the required details.<br>"
> > ."Please go back and enter data in all fields.<br>";
> > echo ".$wName., .$wEmail.";
> > exit;
> > }
> > ?>
> > </body>
> > </HTML>
> >
> > <!-- here is the output from the above code -->
> >
> > You have not entered all the required details.
> > Please go back and enter data in all fields.
> > .., ..

>
> I suppose you entered a Name and Email in sample.html, send it off, and
> then got the error...
> The problem is probably that your server has "register_globals" set to
> "Off", which all new PHP distributions have. That means the $wName and
> $wEmail variables are not available for the simple.php script. You will
> have to use the $_POST variables to get them.
> To fix this problem, just replace $wName and $wEmail with $_POST['wName']
> and $_POST['wEmail'].
>
> DrTebi

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:52 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0