Hello,
I have a problem, that my code runs correctly, insert data to database, but the success message after lastInsertId is not working.
Please help.
What I have tried:
if(isset($_POST['submit']))
{
$class=$_POST['class'];
$subject=$_POST['subject'];
$lesson=$_POST['lesson'];
$topic=$_POST['topic'];
$date = date('Y-m-d');
$teacherid = $_SESSION['teacherid'];
$teachername = $_SESSION['fullname'];
$sql = "INSERT INTO homework (class,subject,lesson,topic,`date`,teacherid,teachername) VALUES(:class,:subject,:lesson,:topic,:date2,:teacherid,:teachername)";
$query=$conn->prepare($sql);
$query->bindparam(':class',$class,PDO::PARAM_STR);
$query->bindparam(':subject',$subject,PDO::PARAM_STR);
$query->bindparam(':lesson',$lesson,PDO::PARAM_STR);
$query->bindparam(':topic',$topic,PDO::PARAM_STR);
$query->bindparam(':date2',$date,PDO::PARAM_STR);
$query->bindparam(':teacherid',$teacherid,PDO::PARAM_INT);
$query->bindparam(':teachername',$teachername,PDO::PARAM_STR);
$query->execute();
$lastInsertId = $conn->lastInsertId();
if($lastInsertId)
{
echo "<script language='text/javascript'>alert('Home work submitted successfully');</script>";
echo "<script type='text/javascript'> document.location = 'index.php'; </script>";
}
}