I'm trying to insert the current logged in users username and the bid they requested into the issue_book database but when I hit the reserve button the message "Book Reserved Successfully" appears but when I check phpMyAdmin nothing appears in the database. Can anyone help me with this please.
<?php
include "footer.php";
include "connection.php";
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<div class= "book-header" style = "padding-top: 2%; padding-left: 1%">
<h2 style = "color: white;">Reserve a Book</h2>
</div>
<div class = "srch" style = "padding-top: 1%; padding-bottom: 1%; padding-left: 1%;">
<form class = "search-button" method = "post" name = "form1">
<div>
<input style= "height: 50px;" class = "" type = "text" name = "bid" placeholder = "Enter Book ID" >
<button style = "background-color: #5db4cb; border: 0; padding: 15px; width: 10%; font-family: sans-serif; color: #ffffff; font-size: 14px; -webkit-transition: all 0.3 ease; transition: all 0.3 ease; cursor: pointer;"
type = "submit" name = "submit1" class = "btn-default">Reserve</button>
</div>
</div>
<?php
if(isset($_POST['submit1']))
{
if(isset($_SESSION['login_user']))
{
mysqli_query($db, "INSERT INTO `issue_book` VALUES('$_SESSION[login_user]', '$_POST[bid]');");
?>
<script type = "text/javascript">
alert("Book Reserved Successfully");
</script>
<?php
}
else{
?>
<script type = "text/javascript">
alert("Need To Login");
</script>
<?php
}
}
?>
<!-- Book Table -->
<?php
$result = mysqli_query($db, "SELECT * FROM books ORDER BY books . name ASC"); // Orders book by name
?>
<table class = 'table table-bordered '>
<tr style='background-color: #abb79b; color: white;'>
<th>ID</th>
<th>Book-Name</th>
<th>Author-Name</th>
<th>Edition</th>
<th>Status</th>
<th>Quantity</th>
<th>Department</th>
</tr>
<?php
while ($row = mysqli_fetch_assoc($result)) {
?>
<tr style = 'background-color: white;'>
<td><?php echo $row['bid'] ?></td>
<td><?php echo $row['name'] ?></td>
<td><?php echo $row['authors'] ?></td>
<td><?php echo $row['edition'] ?></td>
<td><?php echo $row['status'] ?></td>
<td><?php echo $row['quantity'] ?></td>
<td><?php echo $row['department'] ?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>
I think the reason behind the username and bid not inserting into the database might be to do with the query. But I cant see where I have gone wrong so any help would be very appreciated.