New to PDO having trouble with a simple UPDATE feature. Im sure its a simple thing im just over looking it. any help would be much appreciated
<?php
require_once('dbcon.php');
if(isset($_POST['btn_submit'])){
$student_id = $_POST['txt_student_id'];
$student_name = $_POST['txt_student_name'];
$age = $_POST['txt_age'];
$email = $_POST['txt_email'];
$address = $_POST['txt_address'];
$dob = $_POST['txt_dob'];
if(!empty($student_name)){
try {
$stmt = $con->prepare("UPDATE tb_students set student_name= :name,
age = :age,
email = :email,
address = :address,
dob = :dob
WHERE student_id = :student_id");
$stmt->execute(array(':student_name'=>$student_name, ':age'=>$age, ':email'=>$email, ':address'=>$address, ':dob'=>$dob, ':student_id'=>$student_id));
if($stmt){
header('Location:index.php');
}
}catch(PDOException $ex){
echo $ex->getmessage();
}
}else{
echo "INPUT NAME";
}
}
$student_id = 0;
$student_name = '';
$age = 0;
$email = '';
$address = '';
$dob = '';
if(isset($_GET['id'])){
$id = $_GET['id'];
$stmt = $con->prepare('SELECT * FROM tb_students WHERE student_id = :id');
$stmt->execute(array(':id'=>$id));
$row = $stmt->fetch();
$student_id = $row['student_id'];
$student_name = $row['student_name'];
$age = $row['age'];
$email = $row['email'];
$address = $row['address'];
$dob = $row['dob'];
}
?>
<h2>Edit Student</h2>
<form action="" method="post">
<table cellpadding="5px">
<tr>
<tr>
<td>Student Name</td>
<td><input type="text" name="txt_student_name" value="<?=$student_name;?>"></td>
</tr>
<tr>
<td>Age</td>
<td><input type="text" name="txt_age" value="<?=$age;?>"></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="txt_email" value="<?=$email;?>"></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="txt_address" value="<?=$address;?>"></td>
</tr>
<tr>
<td>D.O.B</td>
<td><input type="text" name="txt_dob" value="<?=$dob;?>"></td>
</tr>
<tr>
<td></td>
<td><input type="hidden" name="txt_student_id" value="<?=$student_id;?>"></td>
<td><input type="submit" name="btn_submit"></td>
</tr>
</table>
</form>