Posts: 17
Name: Ali Shan
Location: Pakistan, Lahore
|
I have inserted an email validation script in my web form but it is not working please help me if you can.
Here is my script with html form and php.
PHP Code:
<html> <body bgcolor="silver" text="blue" link="black">
<form action="" method="post"> <table align="center"> <tbody align="left" valign="top"> <tr> <td height="100"></td> </tr> <tr> <td> Name:* </td> <td> <input type="text" name="Name" value="" maxlength="100" /> </td> </tr> <tr> <td> E-Mail:* </td> <td> <input type="text" name="E_Mail" value="" maxlength="100" /> </td> </tr> <tr> <td> Phone no:* </td> <td> <input type="text" name="Ph" value="" maxlength="100" /> </td> </tr> <tr> <td> Ga: </td> <td> <input type="text" name="Ga" value="" maxlength="100" /> </td> </tr> <tr> <td> Comments:* </td> <td> <textarea rows="3" cols="20" name="Comments"></textarea> </td> </tr> <tr> <td> * Required </td> </tr> </table> <table align="center"> <tr> <td> <input type="submit" value="Submit" alt="submit" name="submit" /> </td> <td> <input type="reset" /> </td> </tr> </table> </form>
</body> </html> <?php if (isset($_POST["submit"])) { include("data.php"); $Name=$_POST['Name']; $E_Mail=$_POST['E_Mail']; $Ph=$_POST['Ph']; $Ga=$_POST['Ga']; $Comments=$_POST['Comments']; $error = false; if ($Name == '' || $E_Mail == '' || $Ph == '' || $Comments == '') { $error = true; echo "ERROR: Please fill required fields!"; } if(preg_match("/^[+]{1}[0-9]{12}$/", $Ph)) { $error = false; } else{ echo "The Phone number is not valid."; } if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $E_Mail)) { $error = false; } else{ echo "Your Email is not Valid."; } if($error == false){ mysql_query("INSERT INTO `gmifamil_form`.`gmi` (Name, EMail, Ph, Ga, Comments) VALUES ('$Name', '$E_Mail', '$Ph', '$Ga', '$Comments')") or die(mysql_error()); header("Location: th.htm"); } }
?>
|