Hello ,
Im working in a php form where Im validating the feilds with regular expression. Validation working fine but I want to insert data into database after the validation finish with no error … I dont know how to rite this ?
Im facing a prolem and data is inserting empty records into database each time I click submit. Also , I want after the insert is done to redirect to a Thank you page
here is my code plz help
[php]<?php
$errname = “”;
$errage = “”;
$errmobile = “”;
if($_POST["ac"]=="login"){
// Full Name must be letters, dash and spaces only
if(preg_match("/^[A-Z][a-zA-Z -]+$/", $_POST["name"]) === 0)
$errname = '<p class="errText">Please enter your full name </p>';
// age must be 2 digits
if(preg_match("/^\d{2}$/", $_POST["age"]) === 0)
$errage = '<p class="errText">Age must be 2 digits</p>';
// Mobile mask 050-0000000
if(preg_match("/^\d{3}-\d{7}$/", $_POST["mobile"]) === 0)
$errmobile = '<p class="errText">Mobile must be in this format: 050-0000000</p>';
// contact to database
$connect = mysql_connect(“localhost”, “root”, “”) or die (“Error , check your server connection.”);
mysql_select_db(“career_system”);
//Get data in local variable
$v_name=$_POST[‘name’];
$v_age=$_POST[‘age’];
$v_gender=$_POST[‘gender’];
$v_mobile =$_POST[‘mobile’];
$query=“insert into applicant(name, age, gender, mobile ) values (’$v_name’, ‘$v_age’, ‘$v_gender’,’$v_mobile ')”;
mysql_query($query) or die(mysql_error());
}
echo “Your information has been received”;
}
?>
Full Name | "> | <?php if(isset($errname)) echo $errname; ?> |
Age | "> | <?php if(isset($errage)) echo $errage; ?> |
Gender | Male Female | |
Mobile | "> | <?php if(isset($errmobile)) echo $errmobile; ?> |