0% found this document useful (0 votes)
4 views10 pages

1

The document is a PHP script that manages user submissions for a conference application, ensuring users are logged in and retrieving their details from a database. It includes HTML for a form where users can submit their innovative ideas along with supporting documents and payment details. The script also handles file uploads and validates user input before storing the submission in the database.

Uploaded by

Hirock jyoti Deb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views10 pages

1

The document is a PHP script that manages user submissions for a conference application, ensuring users are logged in and retrieving their details from a database. It includes HTML for a form where users can submit their innovative ideas along with supporting documents and payment details. The script also handles file uploads and validates user input before storing the submission in the database.

Uploaded by

Hirock jyoti Deb
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 10

<?

php

session_start();
// Check if user is logged in
if (!isset($_SESSION['conuserid'])) {
header("Location: user_register.php");
exit();
}

// Database connection details


$host = "localhost";
$user = "root";
$pass = "";
$dbname = "stream22";

// Create database connection


$conn = new mysqli($host, $user, $pass, $dbname);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Fetch user data based on session ID


$user_id = $_SESSION['conuserid'];
// var_dump($user_id);

// SQL query to fetch user details


$sql = "SELECT cfname, clastname, cemail,cmobile FROM conference_users WHERE
cuserno = '$user_id'"; // Fetching first and last name

$result = $conn->query($sql);
// var_dump($result);

if ($result->num_rows > 0) {
// Fetch user details
$user = $result->fetch_assoc();
$first_name = $user['cfname'];
$last_name = $user['clastname'];
$email = $user['cemail'];
$mobile = $user['cmobile'];
$name = $first_name . ' ' . $last_name;
$email = $email;
$mobile = $mobile;
} else {
// Handle the case where user data is not found
echo "User not found.";
exit();
}

// Close the database connection


$conn->close();
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>World Water Day</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="The conference will be held for three days.
14th December 2022 to 16th December 2022">

<link rel="stylesheet" href="css/style.css">


<link rel="stylesheet" href="css/responsive.css">
<link rel="stylesheet" href="style.css">
<script src="js/jquery-1.11.1.min.js"></script>

<style>
.containerbox {
display: flex;
justify-content: center;
align-items: flex-start; /* Align items to the top */
flex-wrap: wrap;
gap: 20px;
padding: 50px 20px;
}

.card {
background: white;
padding: 25px;
border-radius: 12px;
box-shadow: 0px 4px 12px rgba(0, 0, 0, 0.2);
text-align: center;
}

.guidelines {
width: 80%;
/* max-width: 400px; */
text-align: left;
}
.guidelines1 {
width: 100%;
/* max-width: 500px; */
text-align: left;
margin-left:0px
}

.guidelines h2 {
text-align: center;
color: #007BFF;
font-size: 22px;
}

.guidelines ul {
list-style: none;
padding: 0;
}

.guidelines ul li {
padding: 3px;
border-bottom: 1px solid #eee;
font-size:14px
}
.submission-form {
/* width: 55%; */
/* max-width: 500px; */
}

.submission-form h2 {
color: #007BFF;
font-size: 22px;
}

input, textarea {
width: 100%;
padding: 12px;
margin: 10px 0;
border: 1px solid #ccc;
border-radius: 6px;
font-size: 16px;
}

button {
background-color: #007BFF;
color: white;
padding: 12px 16px;
border: none;
border-radius: 6px;
cursor: pointer;
font-size: 16px;
width: 100%;
transition: 0.3s;
}

button:hover {
background-color: #0056b3;
}

form label {
display: block;
text-align: left;
font-weight: bold;
margin-top: 10px;
}

@media (max-width: 768px) {


.containerbox {
flex-direction: column;
}
.guidelines, .submission-form {
width: 90%;
}
}
</style>
</head>
<body>

<?php include 'root/top.php'; ?>


<?php include 'root/header.php'; ?>
<?php include 'root/menu.php'; ?>

<div class="containerbox">
<div class="card guidelines">
<h2><strong>Guidelines</strong></h2>
<ul>
<li>1. Only individual papers will be accepted.</li>
<li>2. Group submissions are not permitted.</li>
<li>3. One person may only submit one paper. .</li>
<li>4. Mode of submission: Online</li>
<li>5. Payment: Online Joining Fee: Rs. 500/-. </li>
<li>6. Age limit: 18–35 years (Aadhar is for verification).
</li>
<li>7. Please upload a screenshot of the payment slip once the amount
has been submitted.</li>
</ul>
</div>

<div class="card submission-form">


<h2><strong>Application Form for BRAHMATHON 2025</strong></h2><br>

<form method="POST" action="" enctype="multipart/form-data">

<div class="card guidelines1">


<h2><strong>Part I - Basic Details </strong></h2>

<label for="purpose_innovative_idea">Propose Innovative Ideas</label>


<input type="text" name="purpose_innovative_idea" placeholder="Type
here" value="" >

<label for="name">Name of the Innovators</label>


<input type="text" name="name" placeholder="Your Name" value="<?php
echo $name; ?>" >

<label for="email">Email</label>
<input type="email" name="email" placeholder="Your Email" value="<?php
echo isset($email) ? $email : ''; ?>" >

<label for="mobile">Mobile No.</label>


<input type="number" name="mobile" placeholder="Your Mobile" value="<?
php echo isset($mobile) ? $mobile : ''; ?>" >

<label for="age">Age (18 to 35 years)</label>


<input type="number" name="age" placeholder="Your age" value="" >

<label for="affiliate">Affiliation (If the participant is not


associated with any institute she/he can mention it as ‘Independent’)</label>
<input type="text" name="affiliate" placeholder="" value="" >

</div><br>

<div class="card guidelines1">


<h2><strong>Part II- Brief Technical Description</strong></h2>

<label for="problem_description_solution">Identify the problem, Describe and


Solution suggested (max 500 words)</label>
<textarea name="problem_description_solution" id="message" placeholder="Type here"
rows="6" ></textarea>

<label for="socio_economic_impact">Socioeconomic impact (max 100 words)</label>


<textarea name="socio_economic_impact" id="message" placeholder="Type here"
rows="6" ></textarea>

<label for="ecological_environment">Ecological & Environmental Relevance (max 100


words)</label>
<textarea name="ecological_environment" id="message" placeholder="Type here"
rows="6" ></textarea>

<label for="attachment"> Please upload max 2 Supporting figures (if any), maximum
image size:5MB:</label>
<input type="file" name="figure2" id="figure2" accept="image/*" >
<input type="file" name="figure3" id="figure3" accept="image/*">

<label for="attachment">Please upload paper/idea presentation (PDF, PPT):</label>


<input type="file" name="attachment" id="attachment" accept=".pdf,.doc,.ppt,.pptx"
>

<label for="figure1">Please upload Adhar/PAN card (Image Only), maximum image


size:5MB:</label>
<input type="file" name="figure1" id="figure1" accept="image/*" >

</div><br>

<!-- <label for="figure2">Upload Figure 2 (Image Only):</label>


<input type="file" name="figure2" id="figure2" accept="image/*" > -->

<div class="card guidelines1">


<h2><strong>Part III - Payment Details</strong></h2>
<h6 style="color:red">*<i>Please make payment in the account details listed
below to successfully submit your application. </i> </h6>

<label>Bank Acount Details:</label>


<input type="text" value="BRAHMAPUTRA BOARD" readonly class="form-
control">

<label>Branch Address:</label>
<input type="text" value="Maidamgaon, Basistha, Kamrup(M) Assam-781029"
readonly class="form-control">

<label>Bank Name:</label>
<input type="text" value="UNION BANK OF INDIA" readonly class="form-
control">

<label>Bank Account Number:</label>


<input type="text" value="394601011001002" readonly class="form-
control">

<label>IFSC Code:</label>
<input type="text" value="UBIN0539465" readonly class="form-control">
<label for="payment_slip">Upload Payment Slip / Screenshot (Image/PDF),
maximum image size:5MB:</label>
<input type="file" name="payment_slip" id="payment_slip"
accept="image/*,.pdf" >

<label for="user_message">Your Message (Max 100 words):</label>


<textarea name="user_message" id="message" placeholder="Your Message"
rows="3" ></textarea>

<button type="submit" name="submit">Submit</button>


</div>

</form>
</div>
</div>

<?php
if (isset($_POST['submit'])) {
// Database connection details
$host = "localhost";
$user = "root";
$pass = "";
$dbname = "stream22";

// Create database connection


$conn = new mysqli($host, $user, $pass, $dbname);

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

// Function to generate a UUID


function UUID4()
{
$bytes = random_bytes(16);
$bytes[6] = chr(ord($bytes[6]) & 0x0f | 0x40);
$bytes[8] = chr(ord($bytes[8]) & 0x3f | 0x80);

return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($bytes), 4));


}

// Get user input


$id = UUID4();
$name = $conn->real_escape_string($_POST['name']);
$email = $conn->real_escape_string($_POST['email']);
$purpose_innovative_idea = $conn-
>real_escape_string($_POST['purpose_innovative_idea']);
$socio_economic_impact = $conn-
>real_escape_string($_POST['socio_economic_impact']);
$affiliate = $conn->real_escape_string($_POST['affiliate']);
$problem_description_solution = $conn-
>real_escape_string($_POST['problem_description_solution']);
$socio_economic_impact = $conn-
>real_escape_string($_POST['socio_economic_impact']);
$ecological_environment = $conn-
>real_escape_string($_POST['ecological_environment']);
$user_message = $conn->real_escape_string($_POST['user_message']);
$age = $conn->real_escape_string($_POST['age']);
$created_at = date("Y-m-d H:i:s");

// File Upload Handling


$uploadDir = "uploads/";

// Ensure the upload directory exists


if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}

// Function to securely upload files


function secureFileUpload($file)
{
global $uploadDir;

// Check if file is uploaded


if (empty($file['tmp_name']) || !is_uploaded_file($file['tmp_name'])) {
return null; // Return null if no file uploaded
}

$allowedMimeTypes = [
'application/pdf',
'application/msword',
'application/vnd.openxmlformats-
officedocument.wordprocessingml.document',
'image/jpeg',
'image/png',
'image/gif'
];

// Get the mime type of the uploaded file


$mime = mime_content_type($file['tmp_name']);

if (!in_array($mime, $allowedMimeTypes)) {
die("Invalid file type: " . htmlspecialchars($file['name']));
}

// Get the file extension and generate a new name


$extension = pathinfo($file['name'], PATHINFO_EXTENSION);
$fileRename = UUID4() . '.' . $extension;
$filePath = $uploadDir . $fileRename;

// Move the file to the upload directory


if (move_uploaded_file($file['tmp_name'], $filePath)) {
return $filePath;
} else {
die("Error uploading file: " . htmlspecialchars($file['name']));
}
}

// Process file uploads


$pdfFilePath = secureFileUpload($_FILES['attachment']);
$figure1Path = secureFileUpload($_FILES['figure1']);
$figure2Path = secureFileUpload($_FILES['figure2']);
$figure3Path = secureFileUpload($_FILES['figure3']);
$paymentSlipPath = secureFileUpload($_FILES['payment_slip']);
// Insert into database
$sql = "INSERT INTO water_day (id, created_at, name,
email,purpose_innovative_idea, mobile, pdfupload, image1upload,
image2upload,image3upload,
payment_slip,age,affiliate,problem_description_solution,socio_economic_impact,ecolo
gical_environment,user_message)
VALUES ('$id', '$created_at', '$name',
'$email','$purpose_innovative_idea','$mobile', '$pdfFilePath', '$figure1Path',
'$figure2Path','$figure3Path',
'$paymentSlipPath','$age','$affiliate','$problem_description_solution','$socio_econ
omic_impact','$ecological_environment','$user_message')";

if ($conn->query($sql) === TRUE) {


echo "<script>alert('Submission Successful!');</script>";

} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

// Close connection
$conn->close();
}
?>

<script>
document.addEventListener("DOMContentLoaded", function () {
const form = document.querySelector("form");
const emailField = document.querySelector('input[name="email"]');
const mobileField = document.querySelector('input[name="mobile"]');
const messageField = document.getElementById("message");
const wordCountDisplay = document.getElementById("wordCount");

form.addEventListener("submit", function (event) {


if (!validateForm()) {
event.preventDefault(); // Prevent form submission if validation
fails
}
});

function validateForm() {
let isValid = true;
let errorMessage = "";

// Name validation
const name = document.querySelector('input[name="name"]').value.trim();
if (name === "") {
errorMessage += "Name is .\n";
isValid = false;
}

// Email validation
const email = emailField.value.trim();
const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]
{2,}$/;
if (!emailPattern.test(email)) {
errorMessage += "Invalid email format.\n";
isValid = false;
}

// Mobile validation
const mobile = mobileField.value.trim();
const mobilePattern = /^[6-9]\d{9}$/;
if (!mobilePattern.test(mobile)) {
errorMessage += "Invalid mobile number. It must be a 10-digit
number starting with 6-9.\n";
isValid = false;
}

// File validation
const validFileExtensions = [".pdf", ".doc", ".ppt", ".pptx"];

const validImageExtensions = [".jpg", ".jpeg", ".png"];


const maxFileSize = 5 * 1024 * 1024; // 5MB

function validateFile(input, validExtensions, type) {


if (input.files.length === 0) {
errorMessage += Please upload ${type}.\n;
isValid = false;
return;
}
const file = input.files[0];
const fileExtension =
file.name.substring(file.name.lastIndexOf(".")).toLowerCase();
if (!validExtensions.includes(fileExtension)) {
errorMessage += Invalid file type for ${type}. Allowed: $
{validExtensions.join(", ")}.\n;
isValid = false;
}
if (file.size > maxFileSize) {
errorMessage += ${type} exceeds the maximum size of 5MB.\n;
isValid = false;
}
}

validateFile(document.getElementById("attachment"),
validFileExtensions, "Document");
validateFile(document.getElementById("figure1"), validImageExtensions,
"Aadhar/PAN card image");
validateFile(document.getElementById("payment_slip"),
validImageExtensions.concat(".pdf"), "Payment Slip");

// Message word count validation


let words = messageField.value.match(/\b\w+\b/g);
let count = words ? words.length : 0;
if (count > 750) {
errorMessage += "Message exceeds 750 words.\n";
isValid = false;
}

if (!isValid) {
alert(errorMessage);
}
return isValid;
}

// Live word count update


messageField.addEventListener("input", function () {
let words = this.value.match(/\b\w+\b/g);
let count = words ? words.length : 0;
wordCountDisplay.textContent = "Word Count: " + count + "/750";

if (count > 750) {


this.value = words.slice(0, 750).join(" ");
wordCountDisplay.textContent = "Word Limit Reached (750/750)";
}
});
});
</script>

<?php include 'root/footer.php'; ?>

<script src="js/slider.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.bxslider.min.js"></script>
<script src="js/jquery.appear.js"></script>
<script src="js/circle-progress.js"></script>
<script src="js/owl.carousel.min.js"></script>
<script src="js/jquery-parallax.js"></script>
<script src="js/validate.js"></script>
<script src="js/jquery.mixitup.min.js"></script>
<script src="js/jquery.fancybox.pack.js"></script>
<script src="js/jquery.easing.min.js"></script>
<script src="js/jquery.countTo.js"></script>
<script src="js/isotope.pkgd.min.js"></script>
<script src="js/jquery-ui-1.11.4/jquery-ui.js"></script>
<script src="js/custom.js"></script>

</body>
</html>

You might also like