<?php
//For database connection
include "includes/conn.php";
$msg="";
//id of record which we want to edit
$id=mysqli_real_escape_string($con,$_GET['id']);
//for form submit
if(isset($_POST['submit'])){
	//Sql injections
	$first_name=mysqli_real_escape_string($con,$_POST['first_name']);
	$last_name=mysqli_real_escape_string($con,$_POST['last_name']);
	$age=mysqli_real_escape_string($con,$_POST['age']);
	//query to update records in database
	$update=mysqli_query($con,"UPDATE `students` SET `first_name`='$first_name',`last_name`='$last_name',`age`='$age' where id ='$id'");
	if(mysqli_affected_rows($con)>0){
		$msg="<div class='alert alert-success'>Record Updated Successfully</div>";
	}
	else{
		$msg="<div class='alert alert-danger'>Record not updated Successfully</div>";
	}
}
//query for retriving the records which we want to edit
$query=mysqli_query($con,"select * from students where id='$id'");
$row=mysqli_fetch_array($query);
?>
<html>
  <head>
	<title> </title>
				<link rel="stylesheet" href="css/bootstrap.min.css">
				<link rel="stylesheet" type="text/css" href="css/style.css">
  </head>
  <body>
<div class="content-wrap">
				<div class="main">
					<div class="container-fluid">
						
						<!-- /# row -->
						<div id="main-content" >

			<div class="row">
				<div class="col-sm-8 offset-2">
						<h1 class="">Edit Student</h1>
					
					<div class="col-sm-12">
					<?php
					echo $msg;
					?>
						<form action="" method="post" role="form" data-toggle="validator">
							<div class="form-group">
								<label>Enter catagories Name</label>
								<input type="text" class="form-control" value="<?php echo $row['first_name']; ?>" name="first_name">
									
							</div>
							<div class="form-group">
								<label>Enter Last Name</label>
								<input type="text" class="form-control" value="<?php echo $row['last_name']; ?>" name="last_name">
									
							</div>
							<div class="form-group">
								<label>Enter Age</label>
								<input type="number" class="form-control" value="<?php echo $row['age']; ?>" name="age">
									
							</div>
						
								
							</div>
							<div class="form-group">
								<input type="submit" class="btn btn-info" value="Update" name="submit">
							</div>
						</form>
					</div>
				</div>
			</div>
				</div>
		</div>
	</div>
		<script src="js/jquery.min.js"></script>
		<script src="js/bootstrap.min.js"></script>
	<body>
</html>
 
		
		
 
	