Jump to content

danielbala

Members
  • Posts

    33
  • Joined

  • Last visited

Everything posted by danielbala

  1. Please Help me to correct my validation code im new to php..
  2. ok im new to forums i dont sorry.. can someone help me to validate all fields..
  3. please help me to correct my code.......i know u can
  4. I CORRETCED THE CODE.. but still not getting the output.. <?php session_start(); // submit button clicked if(isset($_POST['submit'])){ $errors=array(); // Continue when clicked if(isset($_POST['Role'], $_POST['Name'], $_POST['datepicker'], $_POST['gender'], $_POST['activity'], $_POST['Address'], $_POST['Photo'], $_POST['Biodata'], $_POST['certificates'], $_POST['Salary'])){ // Fields are all set else error : No errors conintue // Set variables an sanitise $Emp_Save= mysql_real_escape_string($_POST['Emp_Save']); // Sanitise $Emp_Cancel=$_POST['Emp_Cancel']; // Sanitise $Role=$_POST['Role']; // Sanitise $Name=$_POST['Name']; // Sanitise $datepicker=$_POST['datepicker']; // Sanitise $gender=$_POST['gender']; // Sanitise $activity=$_POST['activity']; // Sanitise $Address=$_POST['Address']; // Sanitise $Photo=$_POST['Photo']; // Sanitise $Biodata=$_POST['Biodata']; // Sanitise $certificates=$_POST['certificates']; // Sanitise $Salary=$_POST['Salary']; // Sanitise //-- Continue with error checks ;; if($_Role == ""){ $errors[]='Please Select The Employee Role!'; } else if(strlen($Name >30)){ $errors[]='Name Is Too Long!'; } else if(empty($Name)) { $errors[]='Please Fill The Field!'; } // Vslidate Datepicker else if(strlen($datepicker) != 10){ $errors[]='Date should only be 10 characters and number .'; } // explode datepaicker by what ever youre using to separate them $datepicker_ex = explode('/', $datepicker); // Check that theyre numbers if(!is_numeric($datepicker_ex[0]) || !is_numeric($datepicker_ex[1]) || !is_numeric($datepicker_ex[2])){ $errors[]='Date should only be number .'; } else { // they are number format them back and cast to int , just incase $datepicker = (int)$datepicker_ex[0].'/'.(int)$datepicker_ex[1].'/'.(int)$datepicker_ex[2]; } // END - date picker valiadation if(empty($gender)){ $errors[]='Please Select The Gender!'; } if(empty($Activity)){ $errors[]='Please Select the Status!'; } if(empty($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(empty($_EmpSalary)){ $errors[]='Please Enter The Salary!'; } //----- End error checks do insert or display errors of any are found -- if(empty($errors)){ // do insert $query = mysql_query("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')"); } else { foreach($errors as $error){ // display errors echo $error; } } //--------------------------------------------------- } else { $errors[]= 'All fields required.'; } } // END -- ?> MOD EDIT: . . . BBCode tags added.
  5. Im not getting any output... I just did the form validation..like.. 1.check all the fields whether they r empty?? 2.validate datepicker 3.validate biodata,certificates fields whether they r empty,uploading file size,file format like it shud upload only pdf format.. 4.validate photo whether they r empty,uploading file size,file format like it shud upload only jpeg,jpg,bmp,gif,png format..
  6. Hi.. Im new to php.. This is my form validate code.. im getting errors...i did my best to do this code Can anyone help me and correct my code <?php session_start(); // submit button clicked if(isset($_POST['submit'])){ $errors=array(); // Continue when clicked if(isset($_POST['Role'], $_POST['Name'], $_POST['datepicker'], $_POST['gender'], $_POST['activity'], $_POST['Address'], $_POST['Photo'], $_POST['Biodata'], $_POST['certificates'], $_POST['Salary'])){ // Fields are all set else error : No errors conintue // Set variables an sanitise $Emp_Save= mysql_real_escape_string($_POST['Emp_Save']); // Sanitise $Emp_Cancel=$_POST['Emp_Cancel']; // Sanitise $Role=$_POST['Role']; // Sanitise $Name=$_POST['Name']; // Sanitise $datepicker=$_POST['datepicker']; // Sanitise $gender=$_POST['gender']; // Sanitise $activity=$_POST['activity']; // Sanitise $Address=$_POST['Address']; // Sanitise $Photo=$_POST['Photo']; // Sanitise $Biodata=$_POST['Biodata']; // Sanitise $certificates=$_POST['certificates']; // Sanitise $Salary=$_POST['Salary']; // Sanitise //-- Continue with error checks ;; 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!'; } // Vslidate Datepicker if(strlen($datepicker) != 10){ $errors[]='Date should only be 10 characters and number .'; } // explode datepaicker by what ever youre using to separate them $datepicker_ex = explode('/', $datepicker); // Check that theyre numbers if(!is_numeric($datepicker_ex[0]) || !is_numeric($datepicker_ex[1]) || !is_numeric($datepicker_ex[2])){ $errors[]='Date should only be number .'; } else { // they are number format them back and cast to int , just incase $datepicker = (int)$datepicker_ex[0].'/'.(int)$datepicker_ex[1].'/'.(int)$datepicker_ex[2]; } // END - date picker valiadation else if($gender == ""){ $errors[]='Please Select The Gender!'; } else if($Activity == ""){ $errors[]='Please Select the Status!'; } else 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.'); } elseif($_EmpSalary == ""){ $errors[]='Please Enter The Salary!'; } //----- End error checks do insert or display errors of any are found -- if(empty($errors)){ // do insert $query = mysql_query("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')"); } else { foreach($errors as $error){ // display errors echo $error; } } //--------------------------------------------------- } else { $errors[]= 'All fields required.'; } } // END -- ?> MOD EDIT: . . . BBCode tags added.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.