I need something simple; I have page where a user clicks an author to see the books associated with that author. On my page displaying the list of books for the author, I want a simple HTML title saying: ‘The books for: AUTHORNAME’
I can get the page to display author ID but not the name. When the user clicks the link in the previous page of the author, it looks likes this:
<a href="viewauthorbooks.php?author_id=<?php echo $row['author_id']?>"><?php echo $row['authorname']?></a>
And then on the ‘viewauthorbooks.php?author_id=23’ I have declared this at the start:
$author_id = $_GET[‘author_id’];
$authorname = $_GET[‘authorname’];
And finally, ‘The books for: AUTHORNAME, where it says AUTHORNAME, I have this:
echo $authorname
(With PHP tags, buts its not letting me put them in!) And this doesnt show anything, however if I change it to author_id, it displays the correct author ID that has been clicked, but its not exactly user friendly!! Can anyone help me out!
You could pull the
author_idfrom the query string as you did using$_GETbut beware you will need to validate what is coming through by the query. I hope you can see that without validation how bad of a security hole this is.I am at work at the moment, but this is a quick example that should give you what you need without sanitizing your query.
The reason why your approach wasn’t working was because you utilize the
$_GETURL parameter passing for author_name where you weren’t supplying the parameters in the URL, just theauthor_id.