<!DOCTYPE html>
<html lang="en">

 <?php include 'head.php';?>

<body>

  <!-- ======= Header ======= -->
  
 <?php include 'menubar.php';?>

 <?php include 'sidebar.php';?>


  <main id="main" class="main">

<!DOCTYPE html>
<html>
<head>
    <title>Student Registration Form</title>
    <link rel="stylesheet" type="text/css" href="styles.css">
	<style>
	body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 20px;
}

h1 {
    text-align: center;
}

form {
    max-width: 500px;
    margin: 0 auto;
}

label {
    display: block;
    margin-top: 10px;
}

input[type="text"],
input[type="date"],
input[type="tel"],
input[type="number"],
textarea,
select {
    width: 100%;
    padding: 10px;
    margin-bottom: 10px;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-sizing: border-box;
}

input[type="submit"] {
    background-color: #4CAF50;
    color: white;
    padding: 10px 20px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    float: right;
}

input[type="submit"]:hover {
    background-color: #45a049;
}
</style>
</head>
<body>
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = mysqli_connect("localhost", "tslibrary_user", "rb!tsl838", "tslibrary_data");
 
// Check connection
if($link === false){
    die("ERROR: Could not connect. " . mysqli_connect_error());
}
 
// Attempt select query execution
$sql = "SELECT  * FROM student_registration order by student_id ASC";
if($result = mysqli_query($link, $sql)){
    if(mysqli_num_rows($result) > 0){
       
        while($row = mysqli_fetch_array($result)){
          
              $studentid=$row['student_id'];
			  
          
        }
    
        // Free result set
        mysqli_free_result($result);
    } else{
        $studentid='10001';
    }
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
 $studentid= $studentid+1;
// Close connection
mysqli_close($link);
?>

<!DOCTYPE html>
<html>
<head>
    <title>Student Registration Form</title>
</head>
<body>
    <h1>Student Registration Form</h1>
    <form action="submit.php" method="post" enctype="multipart/form-data">
		<label>Refer ID:</label>
        <input type="text" name="referno" id='referno' required><br>
		
        <label>Name:</label>
        <input type="text" name="name" id='name' required><br>

        <label>Father's Name:</label>
        <input type="text" name="father" id="father" required><br>

        <label>Mother's Name:</label>
        <input type="text" name="mother"  id="mother" required><br>

        <label>Date of Birth:</label>
        <input type="date" name="dob"  id="dob" required><br>

        <label>Address:</label>
        <textarea name="address"id="address" required></textarea><br>

        <label>Mobile Number:</label>
        <input type="text" name="mobile" id="mobile" required><br>

        <label>Alternate Mobile Number:</label>
        <input type="text" name="mobile2" id="mobile2"><br>

        <label>Aadhar Number:</label>
        <input type="text" name="aadhar" id="aadhar"><br>

        <label>Registration Date:</label>
        <input type="text" name="reg_date" id="reg_date" value='<?php echo date('d/m/Y') ?>' required readonly><br>

        <label>Registration Month:</label>
        <input type="text" name="reg_month" id="reg_month" value='<?php echo date('m') ?>' required readonly><br>

        <label>Registration Year:</label>
        <input type="text" name="reg_year" id="reg_year" value='<?php echo date('Y') ?>'required readonly><br>

        <label>Fees Amount:</label>
        <input type="number" name="fees_amount" id="fees_amount" required><br>
		
		<label>Username:</label>
        <input type="text" name="username" id="username" readonly value='<?php echo $studentid ?>' required><br>
		
		 <label>Password:</label>
        <input type="text" name="password" id="password" required><br>

        <label>Fees Deposit Date:</label>
         <select name="day" id="day">
        <?php
		$todaydate=date('d');
        for ($i = 1; $i <= 31; $i++) {
            echo "<option value='$todaydate'>$todaydate</option>";
			echo "<option value=\"$i\"" . ($i == $dateComponents['day'] ? ' selected' : '') . ">$i</option>";
        }
        ?>
		</select>

  
    <select name="month" id="month">
        <?php
		$todaymonth=date('m');
        for ($i = 1; $i <= 12; $i++) {
			echo "<option value'$todaymonth'>$todaymonth</option>";
            echo "<option value=\"$i\"" . ($i == $dateComponents['month'] ? ' selected' : '') . ">$i</option>";
        }
        ?>
    </select>

        <select name="year" id="year">
        <?php
		$todayyear=date('Y');
        $currentYear = date('Y');
       
			echo "<option value'$currentYear'>$currentYear</option>";
            
       
        ?>
    </select>

 
       
<label for="fees_mode">Fees Mode:</label>
        <select id="fees_mode" name="fees_mode" required>
            <option value="cash">Cash</option>
            <option value="cheque">Cheque</option>
            <option value="online">Online</option>
            <option value="other">Other</option>
        </select><br>


        <label>Student ID:</label>
        <input type="text" name="student_id"  readonly id="student_id" value='<?php echo $studentid ?>'  required><br>

        <label>Batch Time:</label>
        <?php
// Step 1: Connect to the database
$conn = new mysqli("localhost", "tslibrary_user", "rb!tsl838", "tslibrary_data");

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

// Step 2: Retrieve data from the database
$sql = "SELECT batch_time FROM batch";
$result = $conn->query($sql);

// Step 3: Create the dropdown list
if ($result->num_rows > 0) {
    echo '<select name="batch_time" id="batch_time">';
    while ($row = $result->fetch_assoc()) {
        echo '<option value="' . $row["batch_time"] . '">' . $row["batch_time"] . '</option>';
    }
    echo '</select>';
} else {
    echo "No data available.";
}

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

        <label>Upload Photo:</label>
        <input type="file" name="photo" id="photo" accept="image/*" required><br>
 
        <input type="submit" value="Submit">
    </form>
</body>
</html>







   


</body>
</html>

  </main><!-- End #main -->

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

</body>

</html>