Page 1 of 1

code doesn't work

Posted: Sat Jan 02, 2010 7:49 pm
by yb23
<html>
<head>
<title>A BASIC HTML FORM</title>

<?PHP
$username = $_POST['username'];
print ($username);
?>
</head>
<body>

<FORM NAME ="form1" METHOD ="POST" ACTION = "try2.php">

<INPUT TYPE = "TEXT" VALUE ="username" NAME ="username">
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Login">
</FORM>

</body>
</html>

this code suppose to print the word "username"
and in the line below- the input area and "login" button.
why it doesn't work?
thanks.

Re: code doesn't work

Posted: Sat Jan 02, 2010 7:57 pm
by SimpleManWeb
You are posting to try2.php. Based off of the code, it looks like you actually want to post directly to this PHP file, so just set the "action" parameter to nothing and it will post back to itself.

Re: code doesn't work

Posted: Sat Jan 02, 2010 9:07 pm
by Monotoko
here is a nice guide to help with form handling:

http://www.w3schools.com/php/php_forms.asp

Re: code doesn't work

Posted: Sun Jan 03, 2010 4:38 am
by yb23
yes, but it's still doesn't work, the code should view the screen like the attached picture.

Re: code doesn't work

Posted: Sun Jan 03, 2010 7:53 am
by BillAnton
Try this:

Code: Select all

 
<html>
<head>
<title>A BASIC HTML FORM</title>
<?PHP
if  (isset($_POST['username'])) {
$username = $_POST['username'];
print ($username);
}
?>
</head>
<body>
<FORM NAME ="form1" METHOD ="POST" ACTION = "try2.php">
<label for="username">username</label>
<INPUT="username" TYPE = "TEXT" id="username" VALUE ="username" NAME ="username">
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Login"></p>
</FORM>
 
</body>
</html>
 
isset is described here http://www.php.net/manual/en/function.isset.php
Also added and modified some code in the form to complete the syntax.

Regards,
Bill Antonacchio