0

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!';
    }
    }
    }
    ?>
    

Edited by Dani: Formatting fixed

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

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.

0

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??

Edited by danielbala: n/a

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.