Viewing file: gen_certi_data.php (4.16 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<!DOCTYPE html> <html lang="en">
<?php include 'head.php';?>
<body>
<!-- ======= Header ======= --> <?php include 'menubar.php';?>
<?php include 'sidebar.php';?>
<main id="main" class="main">
<div class="pagetitle"> <h1>Dashboard</h1> <nav> <ol class="breadcrumb"> <li class="breadcrumb-item"><a href="index.html">Home</a></li> <li class="breadcrumb-item active">Dashboard</li> </ol> </nav> </div><!-- End Page Title --> <section class="section dashboard"> <?php include 'connect.php';
// Get and sanitize input $roll_no = trim($_POST['roll_no']); $name = trim($_POST['name']); $branchid = trim($_POST['branchid']); $course = trim($_POST['course']); $checkrollno = trim($_POST['cno']); $issue_date = trim($_POST['issue_date']);
// Check for required fields if (empty($roll_no) || empty($name) || empty($branchid) || empty($course)) { echo "<script> alert('Required fields are missing. Please ensure Roll No, Name, Branch ID, and Course are filled.'); window.history.back(); </script>"; exit(); }
// ✅ Check if Certificate No already exists $sql = "SELECT * FROM certificate WHERE CertificateNo='$checkrollno'"; $result = mysqli_query($link, $sql);
if ($result && mysqli_num_rows($result) > 0) { echo "<script> alert('Certificate Number already exists! Please refresh and try again.'); window.location.href='allrecordsshow.php'; </script>"; exit(); } mysqli_free_result($result);
// ✅ Check if Student already has a certificate by Roll No $sql = "SELECT * FROM certificate WHERE Enrollment='$roll_no'"; $result = mysqli_query($link, $sql);
if ($result && mysqli_num_rows($result) > 0) { echo "<script> alert('This student already has a certificate issued!'); window.location.href='allrecordsshow.php'; </script>"; exit(); } mysqli_free_result($result);
// ================== INSERT CERTIFICATE ================== $sql_insert = "INSERT INTO certificate ( Enrollment, Name, branch, Course, pn1, pn1_total_marks, pn1_obtained_marks, pn2, pn2_total_marks, pn2_obtained_marks, pn3, pn3_total_marks, pn3_obtained_marks, pn4, pn4_total_marks, pn4_obtained_marks, pn5, pn5_total_marks, pn5_obtained_marks, pn6, pn6_total_marks, pn6_obtained_marks, pn7, pn7_total_marks, pn7_obtained_marks, pn8, pn8_total_marks, pn8_obtained_marks, pn9, pn9_total_marks, pn9_obtained_marks, pn10, pn10_total_marks, pn10_obtained_marks, certifcate_issue_date, CertificateNo, start_date, end_date, photo, grade ) VALUES ( '$roll_no', '$name', '$branchid', '$course', '{$_POST['pn1']}', '{$_POST['pn1_total_marks']}', '{$_POST['pn1_obtained_marks']}', '{$_POST['pn2']}', '{$_POST['pn2_total_marks']}', '{$_POST['pn2_obtained_marks']}', '{$_POST['pn3']}', '{$_POST['pn3_total_marks']}', '{$_POST['pn3_obtained_marks']}', '{$_POST['pn4']}', '{$_POST['pn4_total_marks']}', '{$_POST['pn4_obtained_marks']}', '{$_POST['pn5']}', '{$_POST['pn5_total_marks']}', '{$_POST['pn5_obtained_marks']}', '{$_POST['pn6']}', '{$_POST['pn6_total_marks']}', '{$_POST['pn6_obtained_marks']}', '{$_POST['pn7']}', '{$_POST['pn7_total_marks']}', '{$_POST['pn7_obtained_marks']}', '{$_POST['pn8']}', '{$_POST['pn8_total_marks']}', '{$_POST['pn8_obtained_marks']}', '{$_POST['pn9']}', '{$_POST['pn9_total_marks']}', '{$_POST['pn9_obtained_marks']}', '{$_POST['pn10']}', '{$_POST['pn10_total_marks']}', '{$_POST['pn10_obtained_marks']}', '$issue_date', '$checkrollno', '{$_POST['start_date']}', '{$_POST['end_date']}', '{$_POST['photo']}', '{$_POST['grade']}' )";
if (!mysqli_query($link, $sql_insert)) { die('Error inserting certificate: ' . mysqli_error($link)); }
// ✅ Update admission table with issue date $update_sql = "UPDATE admission SET certificate_issue_date='$issue_date' WHERE enrollment='$roll_no'"; mysqli_query($link, $update_sql);
mysqli_close($link);
// Success message echo "<script> alert('Student Certificate Generated Successfully'); window.location.href = 'allrecordsshow.php'; </script>"; ?>
</main><!-- End #main -->
<?php include 'footer.php';?>
</body>
</html>
|