Professional Documents
Culture Documents
When Dealing With Forms, The Most Important Aspect To Remember Is That You Are Limited To A Certain Variety of Fields That Can Be Applied To A Form
When Dealing With Forms, The Most Important Aspect To Remember Is That You Are Limited To A Certain Variety of Fields That Can Be Applied To A Form
OF FORMS)
registration.html:
<html>
<head>
<title>Registration form</title>
</head>
<body>
<html>
<form action="get-demo.php" method="GET">
<p>GET Example:</p>
User Name: <input type="text" name="uname"
maxlength="150" /><br /><br />
Password: <input type="password" name="pwd" maxlength="150" /><br />
<input type="submit" value="Submit” />
</form>
</body>
</html>
get.php:
<html>
<head>
<title>Example for get</title>
</head>
<body>
<form action="get-demo.php" method="GET">
<p>GET Example:</p>
User Name: <input type="text" name="uname"
maxlength="150" /><br /><br />
Password: <input type="password" name="pwd" maxlength="150" /><br />
<input type="submit" value="Submit with GET" style="margin-top: 10px;" />
</form>
</body>
</html>
get-demo.php:
<html>
<head>
<title>Example for GET</title>
</head>
<body>
<?php
if ($_GET['submitted'] == "yes"){
if (trim ($_GET['uname']) != "" && trim ($_GET['pwd']) != ""){ echo "Your User Name
(with GET): " . $_GET['uname'];
echo "<br>Your password (with GET) : ". $_GET['pwd'];
} else {
echo "You must submit a value.";
}
?><br /><a href="get.php">Try Again</a><?php
}
?>
</body>
</html>
The trim() function is used to remove the white spaces and other
predefined characters from the left and right sides of a string. Specifies
the character(s) to remove. Without this remove the following " " an
ordinary space.
NOTE:
when using the GET method, hitting the Refresh button after
submitting data the browser will automatically send the data
again.
POST
When sending data using the POST method, values are sent as
standard input (the data will be sended through body not in URL).
Sending data using the POST method is quite a bit more secure .
PHP ’s current methods for dealing with POST variable is the $_POST
superglobal.
Syntax is
$_POST[’Variable Name’];
Post.php:
<html>
<head>
<title>Example for POST</title>
</head>
<body>
<form action="post-demo.php" method="post">
<p>POST Example:</p>
<input type="hidden" name="submitted" value="yes" />
User Name: <input type="text" name="uname" maxlength="150" /><br /><br />
Password: <input type="password" name="pwd" maxlength="150" /><br />
<input type="submit" name="submit" value="Submit with POST" style="margin-top:
10px;" />
</form>
</body>
</html>
Post-demo.php:
<html>
<head>
<title>Example for POST</title>
</head>
<body>
<?php
if(isset($_POST['submitted']))
{
if ($_POST['submitted'] == "yes"){
if (trim ($_POST['uname']) != "" && trim ($_POST['pwd']) != "")
{
echo "Your User Name (with POST): " . $_POST['uname'];
echo "<br>Your password (with POST) : ". $_POST['pwd'];
} else {
echo "You must submit a value.";
}
?><br /><a href="2_get.php">Try Again</a><?php
}
}
?>
</body>
</html>
if($_POST["pwd"]==""){
echo "<font color=red>Please Enter valid Password</font><br>";
}
else if(strlen($_POST["pwd"])<6){
echo "<font color=red>Please Enter valid Password with more than 6
chatrecters<br></font>";
}
}
?>
</head>
<body>
<form method=POST action="<?$_SERVER['PHP_SELF']?>" >
<table>
<tr><td>NAME:</td>
<td><input type=text name="uname" /></td>
</tr>
<tr><td>PASSWORD:</td>
<td><input type=password name="pwd" /></td>
</tr>
<tr><td></td>
<td><input type=hidden name="type" value="Admin" /></td>
</tr>
<tr><td><input type=reset value=CLEAR /></td>
<td><input type=submit value=NEXT /></td>
</tr>
</form>
<?php
if($_SERVER["REQUEST_METHOD"]=
="POST"){
if($_POST["uname"]!="" && strlen($_POST["uname"])>=6 &&
$_POST["pwd"]!="" && strlen($_POST["pwd"])>=6){
echo "Name:<font color=green>".
$_POST['uname']."<br></font>"; echo "Password: <font
color=green>".$_POST['pwd']."<br></font>";
}
}
?>
</body>
</html>
page2.php
<html>
<head>
<title>Contact information</title>
</head><body>
<form method=POST action="page3.php"/>
E-Mail:<input type="text" name="email"/>
Mobile:<input type="text" name="Mobile”/>
ADDRESS:</td><td><textarea name=address></textarea></td>
<input type=hidden name="name" value="<?echo $_POST["name"];?>"
/>
<input type=hidden name="fname" value="<?echo
$_POST["fname"];?>" />
<input type=hidden name="mname" value="<?echo
$_POST["mname"];?>" />
<input type=hidden name="gen" value="<?echo $_POST["gen"];?>" />
<tr>).
<html>
<head>
<title>Complete Information</title>
</head><body>
NAME<?echo $_POST["name"];?>
FATHER NAME</td><td><?echo $_POST["fname"];?>
MOTHER NAME</td><td><?echo $_POST["mname"];?>
GENDER</td><td><?echo $_POST["gen"];?>
E-Mail</td><td><?echo $_POST["email"];?>
<Mobile<?echo $_POST["Mobile"];?>
</body>
</html>
p2.php:
<?php
$name=$_POST['uname'];
$pwd=$_POST['pwd'];
session_start(); if(!
isset($_SESSION['x'])){
$_SESSION['x']=TRUE;
f($_SESSION['x']==TR
UE){
mysql_connect("localhost","root","");
mysql_select_db("TEST");
mysql_query("INSERT INTO login('uname','pwd')
VALUES('$name','$pwd')");
$_SESSION['x']=FALSE;
for($i=0;$i<=2000000;$i++);//donothing
for($i=0;$i<=2000000;$i++);//donothing
for($i=0;$i<=2000000;$i++);//donothing
for($i=0;$i<=2000000;$i+
+);//do
nothing
for($i=0;$i<=2000000;$i++);//do
nothing
}
echo "Successfully added to
database"; session_unset();
?>
</head>
<body>
<form name="test" onsubmit="return checkandsubmit ()" method="post"
action="p2.php"> Name::<input type="text" name="uname"><br>
Password::<input type="password" name="pwd"><br>
<input type="submit" value="SUBMIT" id="submitbut"><br>
</form>
</body>
</html>