I am creating a database wherein users can select a title (search.php)
and then the specific page for that title will be shown with its corresponding details (indiv.php)
.
They will be able to select a title from search.php and here is the code for the title link:
<a href="indiv.php?titleID=' . $row['titleID'] . '">
Then the indiv.php will be able to show the details for that title based on the titleID
they have selected from search.php. Here is the code for indiv.php:
<?php
include "databaseconnect.php";
$titleID = $_GET["titleID"];
$sql = ("SELECT titleID, authorsID, yearID,
FROM table
WHERE titleID = '$titleID'");
$result = $mysqli->query($sql);
$row = mysqli_fetch_assoc($result);
$mysqli->close();
?>
In this indiv.php, I also added a comment section form.
<form action="indiv.php" method="POST">
<input type="text" name="nameID" placeholder="Enter your name" required>
<textarea name="commentID" placeholder="Write your comment here" required></textarea>
<input type="submit" name="submit" value="Post Comment">
</form>
The problem is, every time I try to submit a comment, the page refreshes and does not show its corresponding details (just shows an error - see below) because $titleID = $_GET["titleID"];
cannot fetch the titleID
anymore from search.php
but tries to find it in indiv.php
because of my <form action="indiv.php" method="POST">
in the comment section. Is there a way to prevent this from happening? I want to still be able to show the details based on titleID
even after posting a comment.
The error is: Notice: Trying to access array offset on value of type null in...
Thanks in advance! I am not familiar with PHP so I hope you can help me out.