Complete Class to Insert Data and Upload Image in PHP OOPS
<?php
require('config.php');
class kaamdhenu extends config{
private $preparequery, $executequery;
public function setter(){
$this->executequery = mysqli_query($this->conn,$this->preparequery);
}
function registeruser(){
$this->preparequery = "INSERT INTO kaamdhenu_users(firstName,lastName,password,email,phone,gender,sec_question,sec_answer) VALUES ('".$_POST['fname']."', '".$_POST['lname']."','".$_POST['password']."',
'".$_POST['email']."','".$_POST['phone']."','".$_POST['gender']."','".$_POST['squestion']."','".$_POST['sAnswer']."')";$this->setter();
if($this->executequery){
echo "Successfully Registered";
}
else{
echo "Error";
}
}
public function jobseekerdata(){
$file = $FILES['jobseeker_photo'];
$file1 = $FILES['jobseeker_resume'];
$fileName = $_FILES['jobseeker_photo']['name'];
$fileTmpName = $_FILES['jobseeker_photo']['tmp_name'];
$fileSize = $_FILES['jobseeker_photo']['size'];
$fileError = $_FILES['jobseeker_photo']['error'];
$fileType = $_FILES['jobseeker_photo']['type'];
$fileName1 = $_FILES['jobseeker_resume']['name'];
$fileTmpName1 = $_FILES['jobseeker_resume']['tmp_name'];
$fileSize1 = $_FILES['jobseeker_resume']['size'];
$fileError1 = $_FILES['jobseeker_resume']['error'];
$fileType1 = $_FILES['jobseeker_resume']['type'];
$fileExt = explode('.', $fileName);
$fileExt1 = explode('.', $fileName1);
$fileActualExt = strtolower(end($fileExt));
$fileActualExt1 = strtolower(end($fileExt1));
$allowed = array('jpg', 'jpeg', 'png');
$allowed1 = array('doc', 'docx', 'pdf', 'ppt');
if(in_array($fileActualExt, $allowed) && in_array($fileActualExt1, $allowed1)) {
if($fileError === 0 && $fileError1 === 0){
if($fileSize < 1000000 && $fileSize1 < 5000000) {
$fileNameNew = uniqid('', true).".".$fileActualExt;
$fileNameNew1 = uniqid('', true).".".$fileActualExt1;
$fileDestination = 'uploads/'.$fileNameNew;
$fileDestination1 = 'uploads/'.$fileNameNew1;
move_uploaded_file($fileTmpName, $fileDestination);
move_uploaded_file($fileTmpName1, $fileDestination1);
}
else {
echo "Image File is too big to be uploaded.";
}
$selectemail = "SELECT * FROM kaamdhenu_jobseeker WHERE jobseeker_email ='".$_POST['jobseeker_email']."'";
$query = mysqli_query($this->conn, $selectemail);
$emailcount = mysqli_num_rows($query);
if($emailcount > 0) {
echo "<div class='error_msg'>Email already exists.</div>";
return false;
}
else {
echo "<div id='successmsg'>Registration Successful. Redirecting...</div>";
}
$this->preparequery = "INSERT INTO kaamdhenu_jobseeker(jobseeker_first_name,jobseeker_last_name,jobseeker_email,jobseeker_password,jobseeker_phone,jobseeker_address,jobseeker_state,jobseeker_city,jobseeker_pincode,jobseeker_photo,jobseeker_resume) VALUES ('".$_POST['jobseeker_first_name']."', '".$_POST['jobseeker_last_name']."','".$_POST['jobseeker_email']."',
'".md5($_POST['jobseeker_password'])."',
'".$_POST['jobseeker_phone']."','".$_POST['jobseeker_address']."','".$_POST['jobseeker_state']."','".$_POST['jobseeker_city']."','".$_POST['jobseeker_pincode']."','".$fileDestination."','".$fileDestination1."')";$this->setter();
if($this->executequery){
echo "<div id='successmsg'>Registration Successful. Redirecting...</div>";
}
else{
echo "<div class='error_msg'>Error in regiestering.</div>";
}
}
else {
echo "<div class='error_msg'>Error in uploading image file.</div>";
}
}
else {
echo "<div class='error_msg'>The image/Doc Files of this type could not be uploaded!</div>";
}
}
public function employerdata(){
$file = $FILES['employer_company_pan_card'];
$file1 = $FILES['employer_company_reg_certi'];
$fileName = $_FILES['employer_company_pan_card']['name'];
$fileTmpName = $_FILES['employer_company_pan_card']['tmp_name'];
$fileSize = $_FILES['employer_company_pan_card']['size'];
$fileError = $_FILES['employer_company_pan_card']['error'];
$fileType = $_FILES['employer_company_pan_card']['type'];
$fileName1 = $_FILES['employer_company_reg_certi']['name'];
$fileTmpName1 = $_FILES['employer_company_reg_certi']['tmp_name'];
$fileSize1 = $_FILES['employer_company_reg_certi']['size'];
$fileError1 = $_FILES['employer_company_reg_certi']['error'];
$fileType1 = $_FILES['employer_company_reg_certi']['type'];
$fileExt = explode('.', $fileName);
$fileExt1 = explode('.', $fileName1);
$fileActualExt = strtolower(end($fileExt));
$fileActualExt1 = strtolower(end($fileExt1));
$allowed = array('jpg', 'jpeg', 'png', 'pdf');
$allowed1 = array('jpg', 'jpeg', 'png', 'pdf');
if(in_array($fileActualExt, $allowed) && in_array($fileActualExt1, $allowed1)) {
if($fileError === 0 && $fileError1 === 0){
if($fileSize < 1000000 && $fileSize1 < 5000000) {
$fileNameNew = uniqid('', true).".".$fileActualExt;
$fileNameNew1 = uniqid('', true).".".$fileActualExt1;
$fileDestination = 'uploads/'.$fileNameNew;
$fileDestination1 = 'uploads/'.$fileNameNew1;
move_uploaded_file($fileTmpName, $fileDestination);
move_uploaded_file($fileTmpName1, $fileDestination1);
}
else {
echo "Image File is too big to be uploaded.";
}
$selectemail = "SELECT * FROM kaamdhenu_employer WHERE employer_email ='".$_POST['employer_email']."'";
$query = mysqli_query($this->conn, $selectemail);
$emailcount = mysqli_num_rows($query);
if($emailcount > 0) {
echo "<div class='error_msg'>Email already exists.</div>";
return false;
}
else {
echo "<div id='successmsg'>Registration Successful. Redirecting...</div>";
}
$this->preparequery = "INSERT INTO kaamdhenu_employer(employer_first_name,employer_last_name,employer_email,employer_password,employer_phone,employer_company_name,employer_company_size,employer_company_pan_card,employer_company_reg_certi,employer_address,employer_state,employer_city,employer_pincode) VALUES ('".$_POST['employer_first_name']."','".$_POST['employer_last_name']."','".$_POST['employer_email']."',
'".md5($_POST['employer_password'])."','".$_POST['employer_phone']."','".$_POST['employer_company_name']."','".$_POST['employer_company_size']."','".$fileDestination."','".$fileDestination1."','".$_POST['employer_address']."','".$_POST['employer_state']."','".$_POST['employer_city']."','".$_POST['employer_pincode']."')";
$this->setter();
if($this->executequery){
echo "<div id='successmsg'>Registration Successful. Redirecting...</div>";
}
else{
echo "<div class='error_msg'>Error in regiestering.</div>";
}
}
else {
echo "<div class='error_msg'>Error in uploading image file.</div>";
}
}
else {
echo "<div class='error_msg'>The image Files of this type could not be uploaded!</div>";
}
}
public function login_jobseeker() {
$email = $_POST['jobseeker_email'];
$pass = md5($_POST['jobseeker_password']);
$this->preparequery = "SELECT jobseeker_email,jobseeker_password FROM kaamdhenu_jobseeker WHERE jobseeker_email = '$email' && jobseeker_password = '$pass'";
$data = mysqli_query($this->conn, $this->preparequery);
$row = mysqli_num_rows($data);
if( $row == 1) {
$_SESSION['jobseeker_email'] = $email;
// echo "<div id='successmsg'>Login Successful! Redirecting...</div>";
header('Location:dashboard.php');
}
else {
echo "<div class='error_msg'>Error logging in!</div>";
}
}
public function login_employer() {
$email = $_POST['employer_email'];
$pass = md5($_POST['employer_password']);
$this->preparequery = "SELECT employer_email,employer_password FROM kaamdhenu_employer WHERE employer_email = '$email' && employer_password = '$pass'";
$data = mysqli_query($this->conn, $this->preparequery);
$row = mysqli_num_rows($data);
if( $row == 1) {
$_SESSION['employer_email'] = $email;
echo "<div id='successmsg'>Login Successful! Redirecting...</div>";
// header('Location:dashboard.php');
}
else {
echo "<div class='error_msg'>Error logging in!</div>";
}
}
}
$obj=new kaamdhenu();
?>
Comments
Post a Comment