Displaying the Posts in a Topic

As you may have guessed, the next item on the task list is to build that showtopic.php file, to show the topic's postings. Listing 19.4 does just that.

Listing 19.4. Script to Show Topic Posts
 1: <?php 2: //check for required info from the query string 3: if (!$_GET[topic_id]) { 4: header("Location: topiclist.php"); 5: exit; 6: } 7: 8: //connect to server and select database 9: $conn = mysql_connect("localhost", "joeuser", "somepass") 10: or die(mysql_error()); 11: mysql_select_db("testDB",$conn) or die(mysql_error()); 12: 13: //verify the topic exists 14: $verify_topic = "select topic_title from forum_topics where 15: topic_id = $_GET[topic_id]"; 16: $verify_topic_res = mysql_query($verify_topic, $conn) 17: or ...

Get Sams Teach Yourself PHP, MySQL® and Apache All in One now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.