Login |  Register 
I regularly use your site to answer my PHP problems!
Matt
 

Forms - or doing something a little more useful with PHP

You have seen so far a lot about the structure of PHP but with the use of forms, PHP can allow you to process your users requirements what ever they might be. Below is a standard form which in the action attribute of the form tag has the name of the file that the form currently resides in.
<form action="login.php" method="post">
 <label for="username">Username</label> <input type="text" name="username" />
 <label for="password">Password</label> <input type="password" name="password" />
 <br/><input type="submit" value="Login"/>
</form>
At the top of the file login.php should go the following:
<?php
if (!empty($_POST))
{
 //if the code reaches here it means the form has been posted!
 echo $_POST["username"];
 echo $_POST["password"];
}
?>

Notice that PHP code needs to go within PHP tags. This above code snippet extracts the form values from the post array.

The following line of code:
if (!empty($_POST))
Ensures that there are some post values otherwise it doens't try to read the post array. This is the post array $_POST which contains the form values and this is the name one of the form element that was posted in the above form password.

Comments to date: 13. Page 1 of 2. Average Rating:
jobin   1:56am on Monday, September 3rd, 2018 
jobin
Ramkumar   12:56am on Thursday, April 7th, 2016 
Instead of using isset as every tutorial are teaching to beginners , you are giving !empty() to users so i am voting this as excellent
Jenifer   8:05am on Saturday, April 4th, 2015 
I'd love to JV with Oprah! She's an amazing prmtooer& has the ear of the world. She would be very excited to learn about how I can help so many people suffering with allergies, holistically, &the would give great credibility can you arrange that?
Ahmed Abdallah   8:54am on Saturday, March 21st, 2015 
i think is good article
to read but need more extending of ideas
Deepak kashyap   10:49am on Saturday, October 25th, 2014
common But Good
tushar   1:23am on Tuesday, October 7th, 2014 
superb
Anonymous   11:42pm on Monday, January 20th, 2014 
helpful at very small level.........
Esma   2:13am on Sunday, December 2nd, 2012 
Not bad guys, pretty good isspemrion in my first look around. Far too many pictures of Toyotas though. We're not the Landcruiser club of Victoria! Lets get some patrols up there. Red ones are good
Zaiyah   2:40am on Friday, July 15th, 2011 
Got it! Thanks a lot again for hleipng me out!
dev   4:28am on Thursday, June 30th, 2011 
post some useful programs worst tutorial site i ever seen


Page: -1-   2   

security image
Written by Dominic Skinner
Last Updated: 2011-10-25 16:00:38