index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
include("connect.php");
function test_input($data)
{
$data=trim($data);
$data=stripslashes($data);
$data=htmlspecialchars($data);
return $data;
}
$nameErr=$emailErr=$phoneErr="";
$myname=$myemail=$myphone="";
if($_SERVER['REQUEST_METHOD']=='POST')
{
$flag=1;
if(empty($_POST['name']))
{
$nameErr="* Name is required";
}
else
{
$myname=test_input($_POST['name']);
if(!preg_match("/^[a-zA-Z]*$/",$myname))
{
$flag=0;
$nameErr="* Only letters and white space";
}
}
if(empty($_POST['email']))
{
$emailErr="* email is required";
}
else
{
$myemail=test_input($_POST['email']);
if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$myemail))
{
$flag=0;
$emailErr="* Invalid email id";
}
}
if(empty($_POST['phone']))
{
$phoneErr="* Phone is required";
}
else
{
$myphone=test_input($_POST['phone']);
}
if(($flag==1)&& ($myname!="")&& ($myemail!="")&& ($myphone!=""))
{
$query=mysql_query("INSERT INTO myself VALUES ('','$myname','$myemail','$myphone')");
}
}
?>
<form method="post">
Name:<input name="name" type="text" /><?php echo $nameErr;?><br />
Email:<input name="email" type="text" /><?php echo $emailErr;?><br />
Phone:<input type="text" name="phone" /><?php echo $phoneErr;?><br />
<input type="submit" value="check" name="sub" />
</form>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
include("connect.php");
function test_input($data)
{
$data=trim($data);
$data=stripslashes($data);
$data=htmlspecialchars($data);
return $data;
}
$nameErr=$emailErr=$phoneErr="";
$myname=$myemail=$myphone="";
if($_SERVER['REQUEST_METHOD']=='POST')
{
$flag=1;
if(empty($_POST['name']))
{
$nameErr="* Name is required";
}
else
{
$myname=test_input($_POST['name']);
if(!preg_match("/^[a-zA-Z]*$/",$myname))
{
$flag=0;
$nameErr="* Only letters and white space";
}
}
if(empty($_POST['email']))
{
$emailErr="* email is required";
}
else
{
$myemail=test_input($_POST['email']);
if(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$myemail))
{
$flag=0;
$emailErr="* Invalid email id";
}
}
if(empty($_POST['phone']))
{
$phoneErr="* Phone is required";
}
else
{
$myphone=test_input($_POST['phone']);
}
if(($flag==1)&& ($myname!="")&& ($myemail!="")&& ($myphone!=""))
{
$query=mysql_query("INSERT INTO myself VALUES ('','$myname','$myemail','$myphone')");
}
}
?>
<form method="post">
Name:<input name="name" type="text" /><?php echo $nameErr;?><br />
Email:<input name="email" type="text" /><?php echo $emailErr;?><br />
Phone:<input type="text" name="phone" /><?php echo $phoneErr;?><br />
<input type="submit" value="check" name="sub" />
</form>
</body>
</html>
No comments:
Post a Comment