Imagination is more valuable than knowledge - Albert Einstein
Thursday, August 28, 2008
Navigation
Donate
Has this website helped you?
px
If so, please donate a little to help out with hosting costs.
Members Online
Total Online: 38
Web Spiders: 4
Guests Online: 25
Members Online: 13

Registered Members: 34608
Newest Member: Babaluno
Most Users online: 523
Latest Articles

Simple PHP Form


advertisement



website security Here is a simple PHP form tutorial to help people whom are just starting PHP

What you will need:
Understanding of HTML Forms
Simple Understanding in PHP
A Web host or Apache (http://www.awardspace.com has ok PHP hosting for free)

In this tutorial I will teach all of you who do not already how to create a basic PHP form. So let's begin

First, start with the basic HTML Tags.
<HTML>
<BODY>
<HEAD>
<META>
<TITLE></TITLE>
</HEAD>
</BODY>
</HTML>

After you have your basic HTML done you then need to create a form you do this by putting in the "form" tag and setting up all of the requirements, like this:
<FORM ACTION="Filename Here" METHOD="POST">

The form tag begins the form the action is where the code is being sent.... or outputted. POST is what is happening to the information submitted. In this case it is going to be posted into the web page.

After you have the requirements filled out you must add some input fields. Like this
Username:
<BR>
<Input type="text" name="uname">
<BR>
Password:
<BR>
<input type="password" name="pass">
<BR>
<input type="submit" name="sub" value="SUBMIT">
</FORM>

The text that says Username and Password, is just that, text not some kind of code, also you can add more fields to this. The input commands are very straight forward, it shows what will be inputted to the specified area in this case i will use index.php as an example. So the Username that is inserted into that field will be inputted into the web page, this is the same with the Password field. The "type" tells what kind of text will be inserted, so type="text" means that you will see plain text and type="password" means that you will see password text i.e. ***** then the name(s) specifies what it is... So the name="uname" means that it is part of the "uname" group, the same goes for password.

Now, you need to start out the php.
<?php
?>
That is what you will star with to begin your PHP

Now, you will need to use these commands:
if($_POST['sub'])

{

$u = $_POST['uname'];
$p = $_POST['pass'];

if ($u ="" | $p="");

{
echo 'Please enter a username or password';
}
else
{
echo $_POST['uname'];
echo 'thanks for signing in! Your password is:';
echo $_POST['pass'];
}
}
?>

Basically, this tells the web page what was inputted and tells it what to do with the information. The if command tells what to do "if" something happens, so if it says the beginning code says if ($_POST['sub']) *Note: sub = the name of the submit button* this means that it posts what is submitted. Now, $u = $_POST['uname']; renames the variable, in this case, I changed the variable to u instead of uname, same thing for pass. The if (u="" | p=""); means that if the username has nothing in it or password has nothing in it, it will show up as an error, that I configured with the echo command. The echo command is the command that actually displays something on the webpage through the PHP. The Open brackets { mean that the this is where the code starts then the closed bracket } means the opposite. The closed brackets at the end mean that all the php code is done, then you can end the PHP with ?>

Here is an Example of what the php codes will look like in an actual script:

<HTML>
<BODY>
<HEAD>
<TITLE>HellBoundHackers.org</TITLE>
<STYLE TYPE="TEXT/CSS">
body
{
background-url : ./images/bg
}
a:link {color : black}
</STYLE>
</HEAD>
<FORM ACTION="members.php" METHOD="POST">
Username:
<BR>
<INPUT TYPE="text" NAME="uname" value="">
<BR>
Password
<INPUT TYPE="password" NAME="pass" value="">
<BR>
<INPUT TYPE="SUBMIT" NAME="sub" VALUE="Submit Information">
</FORM>
</Body>
</HTML>

<?php
/***************
*Code By: Coolprogram
****************/

if($_POST['sub'])

{

$uname = $_POST['uname'];
$pass = $_POST['pass'];

if($uname == ''| $pass =='' )

{

echo ' <font color="red">You may have misspelled your username or password</font>';

}

else

{
echo $_POST['uname'];
echo ' thank you for logging in. <BR> Do not forget your password: ';
echo $_POST['pass'];
}

}

?>

I hope this helps some people here with setting up forms in PHP, if you have any questions feel free to PM me.
-Coolprogram

Guest
Username

Password

Remember Me


Bookmark This Page
Affiliates
Adverts

 


By using, viewing or obtaining any information contained on this site, you agree to the disclaimer.

© HellBound Hackers 2007- 2008. Since 3rd December 2004.