Hi there,
I am creating a blogging CMS, and I am stumped on checking whether or not a row exists in a database.
You see, the list of posts are on the home page, and each are a link to its own page.
I have a code that selects the posts from where the post_id is equal to the $_GET[‘view_post_id’].
Well, if the user comes to a URL for a post that has been deleted, I want an error to show up.
How can I do this?
PHP Code:
// Is the user viewing an individual post?
if (isset($_GET['view_post_id'])) {
// Select values from post ID
$row_1 = mysql_query('SELECT * FROM pb_posts WHERE post_id = "' . $_GET['view_post_id'] . '"');
// Show the individual post
while ($row_2 = mysql_fetch_assoc($row_1)) {
echo '<span class="title">' . $row_2['post_title'] . '</span><br>';
echo '<span class="time">' . $row_2['post_date'] . '</span><br>';
echo $row_2['post_body'] . '<br><br>';
echo '<span class="time">Posted by ' . $site->website_author() . ' at ' . $row_2['post_time'] . '</span>';
echo '<br><br><a href="index.php">Return to Home</a>';
}
Thanks,
Eric Johnson