<?php
session_start();
include "config.php";
include "header.php";

if(isset($_POST['save'])){

$name=$_POST['doctor_name'];
$qual=$_POST['qualification'];
$reg=$_POST['reg_no'];
$clinic=$_POST['clinic_name'];
$mobile=$_POST['mobile'];

$sig=$_FILES['signature']['name'];
move_uploaded_file($_FILES['signature']['tmp_name'],
"uploads/".$sig);

$c = mysqli_query($conn,"SELECT id FROM doctor_profile");
if(mysqli_num_rows($c)==0){

mysqli_query($conn,"INSERT INTO doctor_profile
(doctor_name,qualification,reg_no,clinic_name,mobile,signature)
VALUES('$name','$qual','$reg','$clinic','$mobile','$sig')");

}else{

mysqli_query($conn,"UPDATE doctor_profile SET
doctor_name='$name',
qualification='$qual',
reg_no='$reg',
clinic_name='$clinic',
mobile='$mobile',
signature='$sig'
WHERE id=1");
}

echo "<div class='alert alert-success'>Saved</div>";
}

$d = mysqli_fetch_assoc(mysqli_query($conn,"SELECT * FROM doctor_profile LIMIT 1"));
?>

<h3>Doctor Profile</h3>

<form method="post" enctype="multipart/form-data">

Doctor Name:
<input name="doctor_name" value="<?=$d['doctor_name']?>" required>

Qualification:
<input name="qualification" value="<?=$d['qualification']?>">

Registration No:
<input name="reg_no" value="<?=$d['reg_no']?>">

Clinic Name:
<input name="clinic_name" value="<?=$d['clinic_name']?>">

Mobile:
<input name="mobile" value="<?=$d['mobile']?>">

Signature:
<input type="file" name="signature">

<?php if($d['signature']){ ?>
<br>
<img src="uploads/<?=$d['signature']?>" width="120">
<?php } ?>

<br><br>
<button name="save">Save</button>

</form>

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

