hi..
This is form validation code..im getting errors..

  1. I have to check whether all the field r empty and for certificates,photo,biodata field shud be validated for type,size,whether field is empty..

  2. how to validate the datepicker i used javascript

    <?php
    
    session_start();
    
    if(isset($_POST['Role'],$_POST['Name'],$_POST['datepicker'],$_POST['gender'],$_POST['activity'],$_POST['Address'],$_POST['Photo'],$_POST['Biodata']$_POST['certificates'],$_POST['Salary'])) 
    {
    $errors=array();
    $Emp_Save=$_POST['Emp_Save'];
    $Emp_Cancel=$_POST['Emp_Cancel'];
    $Role=$_POST['Role'];
    $Name=$_POST['Name'];
    $datepicker=$_POST['datepicker'];
    $gender=$_POST['gender'];
    $activity=$_POST['activity'];
    $Address=$_POST['Address'];
    $Photo=$_POST['Photo'];
    $Biodata=$_POST['Biodata'];
    $certificates=$_POST['certificates'];
    $Salary=$_POST['Salary'];
    
    
    if($_POST['Emp_Save'])
    {
    $sql="INSERT INTO `formdetails` (role,name,,date_of_birth,gender,activity,address,photo,biodata,certificates,salary) VALUES ('$Role', '$Name','$datepicker',, '$gender','$activity','$Address','$Photo','$Biodata','$certificates','$_EmpSalary')";
    
        $result=mysql_query($sql) or die(mysql_error());
    } 
    
    else
    // check for data in required fields
    if($Role == ""){
        $errors[]='Please Select The Employee Role!';
    }
    
    if(strlen($Name >30){
        $errors[]='Name Is Too Long!';
    }
    else if(empty($Name))
    {
        $errors[]='Please Fill The Field!';
    }
    
    //this to validate date of birth
    if($datepicker == ""){
        $errors[]='Please Select The Date!';
    }
    
    if($gender == ""){
        $errors[]='Please Select The Gender!';
    }
    
    //activity radio button is used
    if($Activity == ""){
        $errors[]='Please Select the Status!';
    }
    
    if($Address == ""){
        $errors[]='Please Enter The Address!';
    }
    
    if(array_key_exists('Photo', $_FILES)) {
     $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.jpeg');
     $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
    // Validate the uploaded file
    if($_FILES['Photo']['size'] === 0 
    || empty($_FILES['Photo']['tmp_name'])) {
        echo("<p>No file was selected.</p>\r\n");
    } else if($_FILES['Photo']['size'] > 50000) {
        echo("<p>The file was too large.</p>\r\n");
    } else if($_FILES['Photo']['error'] !== UPLOAD_ERR_OK) {
        // There was a PHP error
        echo("<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))
          die('The file you attempted to upload is not allowed.');
    }
    
    if(array_key_exists('Biodata', $_FILES)) {
     $allowed_filetypes = array('.pdf');
     $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
    // Validate the uploaded file
    if($_FILES['Biodata']['size'] === 0 
    || empty($_FILES['Biodata']['tmp_name'])) {
        echo("<p>No file was selected.</p>\r\n");
    } else if($_FILES['Biodata']['size'] > 50000) {
        echo("<p>The file was too large.</p>\r\n");
    } else if($_FILES['Biodata']['error'] !== UPLOAD_ERR_OK) {
        // There was a PHP error
        echo("<p>There was an error uploading.</p>\r\n");
    if(!in_array($ext,$allowed_filetypes))
          die('The file you attempted to upload is not allowed.');
    } 
    
    if(array_key_exists('certificates', $_FILES)) {
     $allowed_filetypes = array('.pdf');
     $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
    // Validate the uploaded file
    if($_FILES['certificates']['size'] === 0 
    || empty($_FILES['certificates']['tmp_name'])) {
        echo("<p>No file was selected.</p>\r\n");
    } else if($_FILES['certificates']['size'] > 50000) {
        echo("<p>The file was too large.</p>\r\n");
    } else if($_FILES['certificates']['error'] !== UPLOAD_ERR_OK) {
        // There was a PHP error
        echo("<p>There was an error uploading.</p>\r\n");
    if(!in_array($ext,$allowed_filetypes))
          die('The file you attempted to upload is not allowed.');
    } 
    
    if($Salary == ""){
        $errors[]='Please Enter The Salary!';
    }
    }
    }
    ?>
    

I'm screwed to your code of arrays.... your echoing an empty set of arrays??? and yet arrays cannot echoed.... use print() or print_r() to echo the elements of the arrays. and check if whether it runs an error.

OMG. do not use PHP for that.... you'll have to use JAVASCRIPT

basically in javascipt is where validations forms started and it's good for server computing

can u please correct my code..im new to php
and tried these code to my best..to ceorrect..

im getting lots of errors..

and how to validate the files upload??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.