why the form show twice?
Posted: Tue Nov 19, 2013 10:51 pm
as the title said, i don't know where i have made something wrong, if you feel free tell me please appreciate your help
Code: Select all
<html>
<body>
<form action = 'test2.php' method = 'post'>
<p>Name:<input type = "text" name = "name">
<?php if (isset($_POST["submit"])) {
if (empty($_POST["name"]))
{
echo "Frist name is required";
}
else
{
$_POST["name"] = $_POST["name"];
if (!preg_match("/^[a-zA-Z ]*$/",$_POST["name"]))
{
echo "Only letters and white space allowed";
}
}
}?></p>
<p>Email:<input type = "text" name = "email">
<?php if (isset($_POST["submit"])) {
if (empty($_POST["email"]))
{
echo "Email is required";
}
else
{
$_POST["email"] = $_POST["email"];
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$_POST["email"]))
{
echo "Invalid email";
}
}
}
?></p>
<p><input type = "submit" name = "submit"></p>
</form>
</body>
</html>Code: Select all
<html>
<body>
<?php
$name=$_POST["name"];
$email=$_POST["email"];
if (isset($_POST["submit"])) {
if (empty($_POST["name"]))
{
include("test2.html");
}
else
{
$name = $name;
if (!preg_match("/^[a-zA-Z ]*$/",$name))
{
include("test2.html");
}
}
if (empty($_POST["email"]))
{
include("test2.html");
}
else
{
$email=$email;
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
{
include("test2.html");
}
}
}
?>
</body>
</html>