0

Hi..

This is my validation code

<?php
error_reporting(E_ALL ^ E_NOTICE ^ E_WARNING);
//Process form
if(isset($_POST['Emp_Save'])){

//////////////
//Name//
////////////
	if(isset($_POST['_EmpName'])){
		if(!empty($_POST['_EmpName'])){
			if (preg_match('/([a-zA-Z ]{5,30})/', $_POST['_EmpName'])){
$createaccnt1="t";
			}else{
$createaccnt1="f";
$error1="<span class=\"error\">Five letters or more required</span><br />";
			}
		}else{
$createaccnt1="f";
$error1="<span class=\"error\">Please add your name</span><br />";
		}
	}//if(isset($_POST['_EmpName']))
	
//////////////
//Father Name//
///////////
    if(isset($_POST['_EmpFatherName'])){
		if(!empty($_POST['_EmpFatherName'])){
			if (preg_match('/([a-zA-Z ]{5,30})/', $_POST['_EmpFatherName'])){
$createaccnt2="t";
			}else{
$createaccnt2="f";
$error2="<span class=\"error\">Five letters or more required</span><br />";
			}
		}else{
$createaccnt2="f";
$error2="<span class=\"error\">Please add your fathername</span><br />";
		}
	}//if(isset($_POST['_EmpFatherName']))

if(isset($_POST['_EmpAddress'])){
		if(!empty($_POST['_EmpAddress'])){
			if (preg_match('/([a-zA-Z ]{0,60})/', $_POST['_EmpAddress'])){
$createaccnt3="t";
			}else{
$createaccnt3="f";
$error3="<span class=\"error\">Five letters or more required</span><br />";
			}
		}else{
$createaccnt3="f";
$error3="<span class=\"error\">Please add your address</span><br />";
		}
	}//if(isset($_POST['_EmpAddress']))
	
//////////////
//User Name//
///////////
    if(isset($_POST['_EmpQuali'])){
		if(!empty($_POST['_EmpQuali'])){
			if (preg_match('/([a-zA-Z ]{0,40})/', $_POST['_EmpQuali'])){
$createaccnt4="t";
			}else{
$createaccnt4="f";
$error4="<span class=\"error\">Five letters or more required</span><br />";
			}
		}else{
$createaccnt4="f";
$error4="<span class=\"error\">Please add your Qualification</span><br />";
		}
	}

//////////////
//Salary//
///////////
    if(isset($_POST['_EmpSalary'])){
		if(!empty($_POST['_EmpSalary'])){
			if (!is_numeric($_EmpSalary)){
$createaccnt5="t";
			}else{
$createaccnt5="f";
$error5="<span class=\"error\">Salary Must Be Numeric</span><br />";
			}
		}else{
$createaccnt5="f";
$error5="<span class=\"error\">Please Enter the salary</span><br />";
		}
	}

         if(array_key_exists('_EmpPhoto2', $_FILES)) { 

$allowed_filetypes = array('.jpg','.gif','.bmp','.png','.jpeg','.JPEG','.JPG');
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
// Validate the uploaded file
if($_FILES['_EmpPhoto2']['size'] === 0
|| empty($_FILES['_EmpPhoto2']['tmp_name'])) {
$errors[].="<p>No file was selected.</p>\r\n";
}
if($_FILES['_EmpPhoto2']['size'] > 5242880) {
$errors[].="<p>The file was too large.</p>\r\n";
}
if($_FILES['_EmpPhoto2']['error'] !== UPLOAD_ERR_OK) {
// There was a PHP error
$errors[].="<p>There was an error uploading.</p>\r\n";
}
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes)){
$errors[].='The file you attempted to upload is not allowed.';
//die();
}
}

            if(array_key_exists('_EmpBiodata', $_FILES)) {	
$allowed_filetypes = array('.pdf','.PDF');
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
// Validate the uploaded file
if($_FILES['_EmpBiodata']['size'] === 0
|| empty($_FILES['_EmpBiodata']['tmp_name'])) {
$errors[].="<p>No file was selected.</p>\r\n";
}
if($_FILES['_EmpBiodata']['size'] > 5242880) {
$errors[].="<p>The file was too large.</p>\r\n";
}
if($_FILES['_EmpBiodata']['error'] !== UPLOAD_ERR_OK) {
// There was a PHP error
$errors[].="<p>There was an error uploading.</p>\r\n";
}
if(!in_array($ext,$allowed_filetypes)){
$errors[].='The file you attempted to upload is not allowed.';
//die();
}
}

            if(array_key_exists('_EmpIDproof', $_FILES)) {
$allowed_filetypes = array('.pdf','.PDF');
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
// Validate the uploaded file
if($_FILES['_EmpIDproof']['size'] === 0
|| empty($_FILES['_EmpIDproof']['tmp_name'])) {
$errors[].="<p>No file was selected.</p>\r\n";
}
if($_FILES['_EmpIDproof']['size'] > 5242880) {
$errors[].="<p>The file was too large.</p>\r\n";
}
if($_FILES['_EmpIDproof']['error'] !== UPLOAD_ERR_OK) {
// There was a PHP error
$errors[].="<p>There was an error uploading.</p>\r\n";
}
if(!in_array($ext,$allowed_filetypes)){
$errors[].='The file you attempted to upload is not allowed.';
//die();
}
}
	   if(array_key_exists('_EmpMedIns', $_FILES)) {

$allowed_filetypes = array('.pdf','.PDF');
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
// Validate the uploaded file
if($_FILES['_EmpMedIns']['size'] === 0
|| empty($_FILES['_EmpMedIns']['tmp_name'])) {
$errors[].="<p>No file was selected.</p>\r\n";
}
if($_FILES['_EmpMedIns']['size'] > 5242880) {
$errors[].="<p>The file was too large.</p>\r\n";
}
if($_FILES['_EmpMedIns']['error'] !== UPLOAD_ERR_OK) {
// There was a PHP error
$errors[].="<p>There was an error uploading.</p>\r\n";
}
if(!in_array($ext,$allowed_filetypes)){
$errors[].='The file you attempted to upload is not allowed.';
//die();
}

}
	   	      
	
	   
 //Check flag variables for processing//	
	if (isset($createaccnt1,$createaccnt2,$createaccnt3,$createaccnt4,$createaccnt5,$_FILES['_EmpPhoto2',$_FILES['_EmpBiodata'],$_FILES['_EmpIDproof'],$_FILES['_EmpMedIns']) &&
$createaccnt1=="t" && $createaccnt2=="t" && $createaccnt3=="t" && $createaccnt4=="t"&& $createaccnt5=="t" && ){	  
	   

$_EmpRole = mysql_real_escape_string($_EmpRole);
$_EmpName = mysql_real_escape_string($_EmpName);
$_EmpFatherName = mysql_real_escape_string($_EmpFatherName);
$datepicker = mysql_real_escape_string($datepicker);
$_EmpMaritalStatus = mysql_real_escape_string($_EmpMaritalStatus);
$gender = mysql_real_escape_string($gender);
$_EmpActivityRadio = mysql_real_escape_string($_EmpActivityRadio);
$_EmpAddress = mysql_real_escape_string($_EmpAddress);
$_EmpQuali = mysql_real_escape_string($_EmpQuali);
$_EmpPhoto2 = mysql_real_escape_string($_EmpPhoto2);
$_EmpBiodata = mysql_real_escape_string($_EmpBiodata);
$_DOJoin = mysql_real_escape_string($_DOJoin);
$_EmpIDproof = mysql_real_escape_string($_EmpIDproof);
$_EmpMedIns = mysql_real_escape_string($_EmpMedIns);
$_EmpSalary = mysql_real_escape_string($_EmpSalary);
           // do insert
           $query = mysql_query("INSERT INTO `employeedetails`(emp_role,name,fathername,date_of_birth,marital_status,gender,activity_status,address,qualification,photo,bio_data,date_of_joining,id_proof,medical_insurance_details,salary) VALUES ('$_EmpRole', '$_EmpName','$_EmpFatherName','$datepicker','$_EmpMaritalStatus', '$gender','$_EmpActivityRadio','$_EmpAddress','$_EmpQuali','$_EmpPhoto2','$_EmpBiodata','$_DOJoin','$_EmpIDproof', ,'$_EmpMedIns','$_EmpSalary')");

       } else {
           foreach($errors as $error){
               //  display errors
               echo $error;
           }
       }

       //---------------------------------------------------
   } else {
       $errors[].= 'All fields required.';
   }

//  END --
?>

Can anyone help me..the values r not posted to the table

Edited by danielbala: missed to include details

2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by cereal
0

This is wrong:

$_EmpRole = mysql_real_escape_string($_EmpRole);
$_EmpName = mysql_real_escape_string($_EmpName);
$_EmpFatherName = mysql_real_escape_string($_EmpFatherName);
$datepicker = mysql_real_escape_string($datepicker);
$_EmpMaritalStatus = mysql_real_escape_string($_EmpMaritalStatus);
$gender = mysql_real_escape_string($gender);
$_EmpActivityRadio = mysql_real_escape_string($_EmpActivityRadio);
$_EmpAddress = mysql_real_escape_string($_EmpAddress);
$_EmpQuali = mysql_real_escape_string($_EmpQuali);
$_EmpPhoto2 = mysql_real_escape_string($_EmpPhoto2);
$_EmpBiodata = mysql_real_escape_string($_EmpBiodata);
$_DOJoin = mysql_real_escape_string($_DOJoin);
$_EmpIDproof = mysql_real_escape_string($_EmpIDproof);
$_EmpMedIns = mysql_real_escape_string($_EmpMedIns);
$_EmpSalary = mysql_real_escape_string($_EmpSalary);

change each of that to $_POST[], so you get something like:

$_EmpSalary = mysql_real_escape_string($_POST['_EmpSalary']);
0

Yes I did Still the values r not posted

I think form fields validation code error..
I dont know wr it went wrong..

0

Let's try to simplify the problem. Point the form to a new file in which you just write:

<?php
print_r($_POST);
?>

This way you can check if all the needed values are sent to the script. If this is ok then add the check error block and try to display the results of this check. So at the end of the error block, place: print_r($errors); Once there you should be able to verify what is wrong. Bye.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.