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

 <?php include 'head.php';?>
<style>
body {
    font-family: Arial, sans-serif;
    margin: 0;
    padding: 20px;
}

h1, h2 {
    text-align: center;
}

.branch-list {
    list-style-type: none;
    padding: 0;
    text-align: center;
}

.branch-list li {
    margin: 10px 0;
}

.branch-list a {
    text-decoration: none;
    color: #333;
    font-weight: bold;
}

.branch-list a:hover {
    color: #4CAF50;
}

/* Add more styling as needed */

table {
  border-collapse: collapse;
  border-spacing: 0;
  width: 100%;
  margin: 0 auto;
  border:2;
}

th, td {
  padding: 10px;
  text-align: left;
}

th {
  background-color: #04AA6D;
  color: white;
}
label, input {
  width: 200px;
}
</style>
<body>

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

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


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

<!DOCTYPE html>
<html>
<head>
    <title>Student Search</title>
</head>
<body>

<h2>Search Student by ID</h2>
<form name="Form1" method="get" action="updatefees.php" enctype="text/plain" id="Form1" onsubmit="return ValidateForm1(this)">
<table style="width: 100%">
	<tr>
		<td style="width: 274px; height: 35px">Enter Registration No:</td>
		<td style="height: 35px">
		<form method="post">
			<input name="q" id='q' style="width: 250px" type="text"></form>
		</td>
	</tr>
	<tr>
		<td style="width: 274px">&nbsp;</td>
		<td>
		
			<button name="Submit" type="submit" id="Button1" name="" value="Submit" style="width: 102px">Submit</button>
	
		</td>
	</tr>
</table>
</form>


<?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());
}
 $var = @$_GET['q'];

// Attempt select query execution
$sql = "SELECT * FROM student_registration where student_id='$var'";
if($result = mysqli_query($link, $sql)){
    if(mysqli_num_rows($result) > 0){

        while($row = mysqli_fetch_array($result)){
  
               $studentid= $row['student_id'] ;
               $feesamount=$row['fees_amount'] ;
        }
       
        // Free result set
        mysqli_free_result($result);
    } else{
        echo "Not Available any old Payment";
	exit;	
    }
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
 
// Close connection
mysqli_close($link);
?>

<?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 monthly_fees where student_id='$studentid'";
if($result = mysqli_query($link, $sql)){
    if(mysqli_num_rows($result) > 0){
   echo "<table>";
            echo "<tr>";
                echo "<th>Serial</th>";
                echo "<th>Student ID</th>";
                echo "<th>Month</th>";
                echo "<th>Year</th>";
				 echo "<th>Amount</th>";
				 echo "<th>Date</th>";
            echo "</tr>";
        while($row = mysqli_fetch_array($result))
		{
			
				echo "<tr>";
                echo "<td>" . $row['ID'] . "</td>";
				echo "<td>" . $row['student_id'] . "</td>";
                echo "<td>" . $row['fees_month'] . "</td>";
                echo "<td>" . $row['fees_year'] . "</td>";
                echo "<td>" . $row['fees_amount'] . "</td>";
				echo "<td>" . $row['payment_date'] . "</td>";
				echo "</tr>";
		  $fees_month=date('m');
		  $fees_year=date('Y');
		  $fees_date=date('d/m/Y');
        }
        echo "</table>";
        // Free result set
        mysqli_free_result($result);
    } else{
		
         
		  $fees_month=date('m');
		  $fees_year=date('Y');
		  $fees_date=date('d/m/Y');
    }
} else{
    echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
 
// Close connection
mysqli_close($link);
?>



     <!-- Insert Form -->
    <h2>Insert Fees</h2>
    <form action="insert_fees.php" method="POST">
        <label for="student_id" width='100'>Student ID:</label>
        <input type="text"  width='100' id="student_id" name="student_id" value='<?php echo $studentid ?>' ><br>

        <label for="fees_month"  width='100'>Month:</label>
        <input type="text"  width='100' id="fees_month" name="fees_month" value='<?php echo $fees_month ?>' ><br>

        <label for="fees_year">Year:</label>
        <input type="number" id="fees_year" name="fees_year" value='<?php echo  $fees_year ?>'><br>

        <label for="fees_amount">Fees Amount:</label>
        <input type="number" id="fees_amount" name="fees_amount" value='<?php echo $feesamount ?>'><br>

        <label for="payment_date">Payment Date:</label>
        <input type="text" id="payment_date" name="payment_date" value='<?php echo $fees_date ?>' ><br>

        <input type="submit" value="Insert">
    </form>

   
</body>
</html>


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

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

</body>

</html>