In this system, user should be able to add specialist of their choice after registered through the system. So, when user sign up, the column idSpec will be null. Attribute idSpec is foreign key of specialist table. I've already drop the constraint so that user able to sign up without entering idSpec. After user pick a specialist, then the system will update table user by inserting the id of that particular specialist.
However, when I run the code, it says that the data has been updated but when I check database, it doesn't updated at all.
Here is my code for update function:
<?php
include "dbconfig.php";
$pass = md5($_POST['pass']);
$stmt = $db_con->prepare("UPDATE user SET idUser=:idUser, email=:email, pass=:pass, fName=:fName, lName=:lName, noPhone=:noPhone, address=:address, relationship=:relationship, idStudent=:idStudent, idSpec=:idSpec WHERE idUser=:idUser");
$stmt->bindParam(":idUser", $_POST['idUser']);
$stmt->bindParam(":email", $_POST['email']);
$stmt->bindParam(":pass", $pass);
$stmt->bindParam(":fName", $_POST['fName']);
$stmt->bindParam(":lName", $_POST['lName']);
$stmt->bindParam(":noPhone", $_POST['noPhone']);
$stmt->bindParam(":address", $_POST['address']);
$stmt->bindParam(":relationship", $_POST['relationship']);
$stmt->bindParam(":idStudent", $_POST['idStudent']);
$stmt->bindParam(":idSpec", $_POST['idSpec']);
if ($stmt->execute()) {
$message = "Specialist " .$_POST['idSpec']. " has been successfully registered";
echo"<script type='text/javascript'>alert('$message');</script>";
echo "<script>document.location.href='index.php?user=specialistdetail&idUser=".$_SESSION['idUser']."&idSpec=".$_POST['idSpec']."';</script>";
}
else{
echo "<script>alert('Error');document.location.href='index.php?user=specialistdetail&idUser=".$_SESSION['idUser']."&idSpec=".$_POST['idSpec']."';</script>";
}
?>
Here is the alert after run the code. The number '14' is the idSpec that has just been added.
I'm not sure if the error is in the code or database. Is there any idea or suggestion on how to fix this? Thank you in advance!!