php code for a student results management system using PHP and PDO

In this tutorial, we will learn how to create a php code for a student results management system using PHP and PDO.


student results management system


We need to create an HTML code to prepare a student result sheet with HTML and a bootstrap framework for designs.

We have to build a website to carry the HTML code and get the details and show the result like pass or fail and where you can upload the student data in insert.php page like student name, class, marks in different subjects English, Tamil, Hindi, computer, history, science and one more add the total and pass or fail implementation finalize.
 
$ads={1}

First, we need to create a empty php files

  • dbconfig.php
  • index.php
  • savedata.php
  • fetch.php
  • fetchprocess.php


And then, create a database and I already created and named as "studentresults". 

 

Read also:

 
 
 

 

CREATE A TABLE:



create table student_details
(
    student_id int PRIMARY KEY AUTO_INCREMENT,
    student_name varchar(100) not null,
    class varchar(25) not null,
    English varchar(25) not null,
    Tamil varchar(25) not null,
    Hindi varchar(25) not null,
    computer varchar(25) not null,
    History varchar(25) not null,
    science varchar(25) not null,
   Total varchar(25) not null
);



ALTER TABLE student_id AUTO_INCREMENT = 1000


CREATE DATABASE CONNECTION (dbcofig.php):



<?php

    $hostname = "localhost";
    $username = "root";
    $password = "";

    try {
        $conn = new PDO("mysql:host=$hostname;dbname=studentresults", $username, $password);
        // set the PDO error mode to exception
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        //echo "Database connected successfully";
    } catch(PDOException $e) {
        echo "Database connection failed: " . $e->getMessage();
    }

?>


CREATE index.php PAGE:



<body>
<div class="container py-5">
<h1 class="text-center">Student Marksheet Insert</h1><br/>
<div id="success" class="alert alert-success close" style="display:none;">

</div>
 
<fieldset>
<div class="row py-5">
  <div class="col">
    <input type="text" id="name" class="form-control" placeholder="Student Name">
  </div>
  <div class="col">
    <input type="text" id="stdclass" class="form-control" placeholder="Class" >
  </div>
</div>
</fieldset>

<table class="table table-bordered" >
 <thead>
    <tr>
      <th scope="col" colspan="6" class="text-center">Insert Student Marks</th>
    </tr>
	<tr>
            <th>English</th>
            <th>Tamil</th>
            <th>Hindi</th>
            <th>Computer</th>
			<th>History</th>
			<th>Science</th>
        </tr>
  </thead>
  <tbody>
  <tr>
  
<td><input type="text" id="english" class="form-control" ></td>
<td><input type="text" id="tamil" class="form-control" ></td>
<td><input type="text" id="hindi" class="form-control" ></td>
<td><input type="text" id="computer" class="form-control" ></td>
<td><input type="text" id="history" class="form-control" ></td>
<td><input type="text" id="science" class="form-control" ></td>


  </tr>
  <tr>
  <td colspan="6">
  <div class="d-grid col-6 mx-auto gap-2">
  <input type="submit" id="save" class="btn btn-primary" name ="save" value="Insert Data">
  <input type="reset" id="reset" class="btn btn-danger" name="reset" value="Reset"/>
  </div>
  </td>
  </tr>
  </tbody>
</table>
</div>
</body>


student results management system


INSERT DATA INTO DATABASE USING JQUERY:



<script type="text/javascript">
$(document).ready(function(){
	$('#save').on('click',function(){
		var name = $('#name').val();
		var stdclass = $('#stdclass').val();
		var english = $('#english').val();
		var tamil = $('#tamil').val();
		var hindi = $('#hindi').val();
		var computer = $('#computer').val();
		var history = $('#history').val();
		var science = $('#science').val();
		var totalMarks = parseInt(english)+parseInt(tamil)+parseInt(hindi)+parseInt(computer)+parseInt(history)+parseInt(science);
if(name!='' && stdclass!='' && english!='' && tamil!='' && hindi!='' && computer!='' && history!='' && science!='')
	{
		$.ajax({
			url: "savedata.php",
			type:"POST",
			data:{
				name:name,
				stdclass:stdclass,
				english:english,
				tamil:tamil,
				hindi:hindi,
				computer:computer,
				history:history,
				science:science,
				totalMarks:totalMarks,
				result:result
			},
			cache:false,
			success:function(data){
				$('#success').show();
				$('#success').html(data);
				window.setTimeout(function() {
                $(".close").fadeTo(100, 0).slideUp(100, function(){
                $(this).remove(); 
    });
}, 5000);
			} 
	});		
}
	else{
		alert('Please All the fields');
	}
			
});
 $('#reset').click(function() {
        $(':input')
            .not(':button, :submit, :reset, :hidden')
            .val('')
            .removeAttr('checked')
            .removeAttr('selected');
    });
});
</script>


CREATE savedata.php FILE:



<?php
	include 'dbconfig.php';

	$name=$_POST['name'];
	$stdclass=$_POST['stdclass'];
	$english=$_POST['english'];
	$tamil=$_POST['tamil'];
	$hindi=$_POST['hindi'];
	$computer=$_POST['computer'];
	$history=$_POST['history'];
	$science=$_POST['science'];
	$total = $_POST['totalMarks'];
	$result = $_POST['result'];
	
	$stmt = "INSERT INTO student_details (student_name,class,English,Tamil,Hindi,computer,History,science,Total,Result) values(:name,:stdclass,:english,:tamil,:hindi,:computer,:history,:science,:total,:result)";
	$sql = $conn->prepare($stmt);
	$sql->bindParam(':name',$name,PDO::PARAM_STR);
	$sql->bindParam(':stdclass',$stdclass,PDO::PARAM_INT);
	$sql->bindParam(':english',$english,PDO::PARAM_INT);
	$sql->bindParam(':tamil',$tamil,PDO::PARAM_INT);
	$sql->bindParam(':hindi',$hindi,PDO::PARAM_INT);
	$sql->bindParam(':computer',$computer,PDO::PARAM_INT);
	$sql->bindParam(':history',$history,PDO::PARAM_INT);
	$sql->bindParam(':science',$science,PDO::PARAM_INT);
	$sql->bindParam(':total',$total,PDO::PARAM_INT);
	$sql->bindParam(':result',$result,PDO::PARAM_STR);
	
	if($sql->execute()) 
	{
    echo "Data are successfully Inserted...!";
    }
	else
	{
		echo "Insert is problem ";
	}
		
	
?>


student results management system




CREATE fetch data (fetch.php):


In this fetch.php is used to get the details for student results using student_id .when the student_id is entered in the input field and click the get results button .It will show the results.

student results management system

<body>

<div class="container mt-2 py-5">
<h1 class="text-center">Student Results</h1>
    <div class="row py-5">
        <div class="col-md-12">
            <div class="card">
              <div class="card-header">
               Get Data From Database in PHP PDO using Id
              </div>
              <div class="card-body">
        <form method="get" class="form-control mb-3" action="fetchprocess.php">
       <label for="exampleFormControlInput1" class="form-label py-3 text-center">Enter Register No:</label>
        <input type="text" name="register_no" class="form-control"/>
        <br />
        <div class="text-center">
        <input class="btn btn-lg btn-primary" type="submit" value="Get Results" name="submit"/>
        </div>

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

</body>


CREATE FILE FTECH STUDENT RESULTS DATA(fetchprocess.php):



<?php
include 'dbconfig.php';
if(isset($_GET['register_no'])){
	  $sth = $_GET['register_no'];

	  $sql = $conn->prepare("SELECT * FROM student_details where student_id = :student_id");
	  $sql->execute(['student_id' => $sth]);
      $results = $sql->fetchAll();

foreach($results as $result)
{
?>


student results management system
student results management system


RESULT HTML TABLE:



<body>
<div class="container py-5">
<a href="fetch.php" class="btn btn-primary">Back</a>
<h1 class="text-center">Student Results</h1>
<table class="table table-bordered">
<tr>
<td><strong>Register No:</strong></td>
<td><?php echo $result['student_id']; ?></td>
</tr>
<tr>
<td><strong>Name:</strong></td>
<td><?php echo $result['student_name']; ?></td>
</tr>
<tr>
<td><strong>Class:</strong></td>
<td><?php echo $result['class']; ?></td>
</tr>
</table>
<div class="text-success py-3">
<hr>
</div>
<table class="table table-bordered">
<th>Subject</th>
<th>Marks</th>
<th>Result</th>
<tr>
<td>English</td>
<td><?php echo $result['English']; ?></td>
<td>
<?php
if($result['English'] >=35)
{
	echo '<font color="green">Pass</font>';
}
else
{
	echo '<font color="red">Fail</font>';
}
?>
</td>
</tr>
<tr>
<td>Tamil</td>
<td><?php echo $result['Tamil']; ?></td>
<td>
<?php
if($result['Tamil'] >=35)
{
	echo '<font color="green">Pass</font>';
}
else
{
	echo '<font color="red">Fail</font>';
}
?>
</td>
</tr>
<tr>
<td>Hindi</td>
<td><?php echo $result['Hindi']; ?></td>
<td>
<?php
if($result['Hindi'] >=35)
{
	echo '<font color="green">Pass</font>';
}
else
{
	echo '<font color="red">Fail</font>';
}
?>
</td>
</tr>
<tr>
<td>Computer</td>
<td><?php echo $result['computer']; ?></td>
<td>
<?php
if($result['computer'] >=35)
{
	echo '<font color="green">Pass</font>';
}
else
{
	echo '<font color="red">Fail</font>';
}
?>
</td>
</tr>
<tr>
<td>History</td>
<td><?php echo $result['History']; ?></td>
<td>
<?php
if($result['History'] >=35)
{
	echo '<font color="green">Pass</font>';
}
else
{
	echo '<font color="red">Fail</font>';
}
?>
</td>
</tr>
<tr>
<td>Science</td>
<td><?php echo $result['science']; ?></td>
<td>
<?php
if($result['science'] >=35)
{
	echo '<font color="green">Pass</font>';
}
else
{
	echo '<font color="red">Fail</font>';
}
?>
</td>
</tr>
<tr>
<td class="text-center"><b>Total</b></td>
<td><?php echo $result['Total']; ?></td>
<td>
</td>
</tr>
</table>


<?php
}}	 
	?>  
	  
</div>
</body>
  


student results management system


Previous Post Next Post