ÿØÿà JFIFÿØÿà JFIF ÿØÿà JFIFÿØÿà JFIF ÿþ$
<?php
include('config.php');
session_start();
$cname = '';
$age = '';
$email = '';
$pname = '';
$phone = '';
$me = '';
$error = '';
// Allow only POST requests
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['submit'])) {
// Sanitize all inputs
$cname = trim(mysqli_real_escape_string($conn, $_POST['cname'] ?? ''));
$age = intval($_POST['age'] ?? 0);
$email = trim(mysqli_real_escape_string($conn, $_POST['email'] ?? ''));
$parents = trim(mysqli_real_escape_string($conn, $_POST['pname'] ?? ''));
$phone = preg_replace('/[^0-9+]/', '', $_POST['phone'] ?? '');
$phone2 = preg_replace('/[^0-9+]/', '', $_POST['phone2'] ?? '');
// Basic validation
if (empty($cname) || empty($email) || empty($parents) || empty($phone)) {
$error = 'All required fields must be filled.';
} elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$error = 'Invalid email address.';
}
if (empty($error)) {
// Check if email or phone already exists
$stmt = $conn->prepare("SELECT Id FROM registration WHERE Email = ? OR Phone = ?");
$stmt->bind_param("ss", $email, $phone);
$stmt->execute();
$stmt->store_result();
if ($stmt->num_rows > 0) {
$error = 'This E-mail or Phone Number Already Exists';
} else {
// Get next ID safely (avoid manual increment)
$sqle = $conn->query("SELECT Id FROM registration ORDER BY Id DESC LIMIT 1");
$row = $sqle->fetch_assoc();
$id = ($row) ? intval($row['Id']) + 1 : 1;
// Insert securely
$sqli = $conn->prepare("INSERT INTO registration (Id, Childsname, Age, Email, Parentsname, Phone, Phone2) VALUES (?, ?, ?, ?, ?, ?, ?)");
$sqli->bind_param("isissss", $id, $cname, $age, $email, $parents, $phone, $phone2);
if ($sqli->execute()) {
$_SESSION['bug'] = 'Registered';
$_SESSION['Id'] = $id;
$_SESSION['email'] = $email;
// --- Image Upload Securely ---
if (isset($_FILES['pic']) && $_FILES['pic']['error'] === UPLOAD_ERR_OK) {
$img_name = $_FILES['pic']['name'];
$img_size = $_FILES['pic']['size'];
$temp_name = $_FILES['pic']['tmp_name'];
$error_code = $_FILES['pic']['error'];
$allowed_types = ['image/jpeg', 'image/png', 'image/jpg'];
$file_type = mime_content_type($temp_name);
if (!in_array($file_type, $allowed_types)) {
$me = "Invalid image type. Only JPG and PNG allowed.";
} elseif ($img_size > 3 * 1024 * 1024) {
$me = "Picture is larger than 3MB.";
} elseif ($error_code !== UPLOAD_ERR_OK) {
$me = "There was an error with the image upload.";
} else {
$ext = strtolower(pathinfo($img_name, PATHINFO_EXTENSION));
$new_img_name = $id . '.' . $ext;
$upload_dir = __DIR__ . '/c_image/';
if (!is_dir($upload_dir)) {
mkdir($upload_dir, 0755, true);
}
$img_upload_path = $upload_dir . $new_img_name;
if (move_uploaded_file($temp_name, $img_upload_path)) {
$new_img_nam = 'c_image/' . $new_img_name;
$update = $conn->prepare("UPDATE registration SET Image = ? WHERE Id = ?");
$update->bind_param("si", $new_img_nam, $id);
$update->execute();
echo "<script>alert('Your registration was successful!');</script>";
echo "<script>location.href='card.php';</script>";
exit;
} else {
$me = "Failed to move uploaded file.";
}
}
} else {
$me = "No image uploaded or an upload error occurred.";
}
} else {
$error = 'Something went wrong. Please try again.';
}
}
}
}
// Display errors if any
if (!empty($error)) {
echo "<p style='color:red; font-weight:bold;'>" . htmlspecialchars($error) . "</p>";
}
if (!empty($me)) {
echo "<p style='color:red; font-weight:bold;'>" . htmlspecialchars($me) . "</p>";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=AW-16759433870">
</script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'AW-16759433870');
</script>
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-DWZP5NWRWX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-DWZP5NWRWX');
</script>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<?php
include('nav.php');
?>
</head>
<style>
/* From uiverse.io by @ShadowShahriar */
button {
--border-radius: 15px;
--border-width: 4px;
appearance: none;
position: relative;
padding: 1em 2em;
border: 0;
background-color: transparent;
color:#560280;
font-family: "Roboto", Arial, "Segoe UI", sans-serif;
font-size: 18px;
font-weight: 500;
color: #fff;
z-index: 2;
}
button::after {
--m-i: linear-gradient(#000, #000);
--m-o: content-box, padding-box;
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
padding: var(--border-width);
border-radius: var(--border-radius);
color:#560280;
background-image: conic-gradient(
#488cfb,
#29dbbc,
#ddf505,
#ff9f0e,
#e440bb,
#655adc,
#488cfb
);
-webkit-mask-image: var(--m-i), var(--m-i);
mask-image: var(--m-i), var(--m-i);
-webkit-mask-origin: var(--m-o);
mask-origin: var(--m-o);
-webkit-mask-clip: var(--m-o);
mask-composite: exclude;
-webkit-mask-composite: destination-out;
filter: hue-rotate(0);
animation: rotate-hue linear 500ms infinite;
animation-play-state: paused;
}
button:hover::after {
animation-play-state: running;
color:#560280;
}
@keyframes rotate-hue {
to {
filter: hue-rotate(1turn);
}
}
button,
button::after {
box-sizing: border-box;
}
button:active {
--border-width: 5px;
}
</style>
<body>
<div class="row container">
<div class="col l6 m12 s12">
<br>
<br>
<br>
<br>
<br>
<form style="border-color:#560280; border-style:solid; border-width:2px; border-radius:10px; padding: 10px" action="" method="POST" id="reg" enctype="multipart/form-data">
<?php if (isset($error)) {?>
<div>
<?php echo $error ?>
</div>
<?php }?>
<?php if ($me!=0) {?>
<div>
<?php echo $me ?>
</div>
<?php }?>
<div class="row">
<div class=" col l12 m12 s12 input-field ">
<label for="cname">Contestant's Name</label>
<input maxlength="16" type="text" name="cname" id="cname" required="value" value="<?php echo $cname ?>">
</div>
<div class="input-field col l12 m12 s12 ">
<select type="select" id="age" name="age" required value="<?php echo $age ?>">
<option value="" disabled selected>Contestant's Age</option>
<option value="1 Month Old">1 Month</option>
<option value="2 Months Old">2 Months</option>
<option value="3 Months Old">3 Months</option>
<option value="4 Months Old">4 Months</option>
<option value="5 Months Old">5 Months</option>
<option value="6 Months Old">6 Months</option>
<option value="7 Months Old">7 Months</option>
<option value="8 Months Old">8 Months</option>
<option value="9 Months Old">9 Months</option>
<option value="10 Months Old">10 Months</option>
<option value="11 Months Old">11 Months</option>
<option value="1 Year">1 Year</option>
<option value="2 Years">2 Years</option>
<option value="3 Years">3 Years</option>
<option value="4 Years">4 Years</option>
<option value="5 Years">5 Years</option>
<option value="6 Years">6 Years</option>
<option value="7 Years">7 Years</option>
<option value="8 Years">8 Years</option>
<option value="9 Years">9 Years</option>
<option value="10 Years">10 Years</option>
<option value="11 Years">11 Years</option>
<option value="12 Years">12 Years</option>
</select>
</div>
</div>
<div class="row">
<div class="col l6 m6 s12 input-field ">
<label for="email">E-mail</label>
<input type="email" name="email" id="email" required="validate" value="<?php echo $email ?>">
</div>
<div class="col l6 m6 s12 input-field ">
<label for="phone">Mum's Whatsapp Number</label>
<input type="tel" name="phone" required="value" id="phone" maxlength="11" value="<?php echo $phone ?>">
</div>
</div>
<div class="row">
<div class="col l6 m6 s12 input-field ">
<label for="phone2">Dad's Whatsapp Number</label>
<input type="tel" name="phone2" required="value" id="phone2" maxlength="11" value="<?php echo $phone ?>">
</div>
<div class="col l6 m6 s12 input-field ">
<label for="pname">Parent's Name</label>
<input type="text" name="pname" id="pname" required="value" value="<?php echo $pname ?>">
</div>
<br>
<br>
<br>
<div class="center">
<label>Please upload a <span style="color:#560280">SQUARE SHAPED</span> picture for clarity</label>
<div class="photo ">
<div>
<input style="border-color:#560280; border-style:solid; border-width:2px; border-radius:10px; padding: 10px" type="file" name="pic" required >
</div>
<input type="hidden" name="Id" value="<?php //echo $user_id ?>">
</div>
<br>
<button style="color:#560280;" name="submit" type="submit" >Register</button>
</div>
</form>
</div>
</div>
<div class="col l4 m10 s10 push-l1">
<img src="img/portrait-g32c4ff260_1280-removebg-preview.png" alt="">
</div>
</div>
</body>
<?php include('footer.php')?>
</html>
ÿØÿà JFIF ÿþ$
ÿØÿà JFIF ÿþ$
ÿÂ