Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Try this. Edited to the final answer.</p> <p><strong>button</strong>:</p> <pre><code>&lt;div class= "obutton feature2" data-id="&lt;?php echo $bookID;?&gt;"&gt; &lt;button class="reserve-button"&gt;Reserve Book&lt;/button&gt; &lt;/div&gt; </code></pre> <p><strong>script</strong>:</p> <pre><code>&lt;script&gt; $('.reserve-button').click(function(){ var book_id = $(this).parent().data('id'); $.ajax ({ url: 'reservebook.php', data: {"bookID": book_id}, type: 'post', success: function(result) { $('.modal-box').text(result).fadeIn(700, function() { setTimeout(function() { $('.modal-box').fadeOut(); }, 2000); }); } }); }); &lt;/script&gt; </code></pre> <p><strong>reservebook.php</strong>:</p> <pre><code>&lt;?php session_start(); $conn = mysql_connect('localhost', 'root', ''); mysql_select_db('library', $conn); if(isset($_POST['bookID'])) { $bookID = $_POST['bookID']; $result = mysql_query("INSERT INTO borrowing (UserID, BookID, Returned) VALUES ('".$_SESSION['userID']."', '".$bookID."', '3')", $conn); if ($result) echo "Book #" + $bookId + " has been reserved."; else echo "An error message!"; } ?&gt; </code></pre> <p><strong>PS#1</strong>: The change to <code>mysqli</code> is minimal to your code, but strongly recommended.</p> <p><strong>PS#2</strong>: The <code>success</code> on Ajax call doesn't mean the <code>query</code> was successful. Only means that the Ajax transaction went correctly and got a satisfatory response. That means, it sent to the <code>url</code> the correct data, but not always the <code>url</code> did the correct thing.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload