code doesn't work

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yb23
Forum Newbie
Posts: 3
Joined: Sat Jan 02, 2010 7:08 pm

code doesn't work

Post 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.
User avatar
SimpleManWeb
Forum Commoner
Posts: 57
Joined: Wed Dec 30, 2009 4:15 pm
Location: New Hampshire, USA

Re: code doesn't work

Post 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.
Monotoko
Forum Commoner
Posts: 64
Joined: Fri Oct 26, 2007 4:24 pm

Re: code doesn't work

Post by Monotoko »

here is a nice guide to help with form handling:

http://www.w3schools.com/php/php_forms.asp
yb23
Forum Newbie
Posts: 3
Joined: Sat Jan 02, 2010 7:08 pm

Re: code doesn't work

Post by yb23 »

yes, but it's still doesn't work, the code should view the screen like the attached picture.
Attachments
basicFormPost2.jpg
basicFormPost2.jpg (22.7 KiB) Viewed 31 times
BillAnton
Forum Newbie
Posts: 7
Joined: Fri Jan 01, 2010 2:02 pm

Re: code doesn't work

Post 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
Post Reply