I am trying to add some features on an old project. But this happens when i try to edit some data. Any Idea where I am getting wrong.
My code
<?php
//session already set in config file
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
include('config/db.php');
//Editform query to populate data to the form
$id = $_GET['id'];
$sql = "SELECT * FROM bloodgroups WHERE id=:id";
$query = $dbh -> prepare($sql);
$query -> execute([':id' => $id ]);
$result = $query ->fetch();
//Edit query to update the data
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$blood_group = $_POST['blood_group'] ;
$sql = "UPDATE bloodgroups set blood_group = :blood_group WHERE id=:id";
$query = $dbh -> prepare($sql);
if ($query -> execute([':blood_group' => $blood_group, ':id' => $id])) {
header("location: index.php");
}
}
?>
<?php include('routes/header.php');?>
<?php include('routes/topbar.php');?>
<?php include('routes/sidebar.php');?>
<div class="content-wrapper">
<div class="content-header">
<div class="container-fluid">
<div class="row mb-2">
<div class="col-sm-6">
</div>
</div>
</div>
</div>
<section class="content">
<div class="container-fluid">
<div class="row">
<div class="col-8">
<div class="card">
<div class="card-header">
EditBlood
</div>
<div class="card-body">
<form class="form-inline" action="" id="form" method="POST">
<div class="form-group mx-sm-3 mb-2">
<input type="text" value="<?= $result->blood_group; ?>" name="blood_group" id="blood_group" class="form-control" >
</div>
<button type="submit" class="btn btn-primary mb-2">Submit</button>
</form>
</div>
</div>
</div>
</div>
</div>
</section>
</div>
<?php include_once 'routes/footer.php';?>