Linking Post Title to Specific Page ID

Posted by ThatMacLad on Stack Overflow See other posts from Stack Overflow or by ThatMacLad
Published on 2010-04-21T16:09:18Z Indexed on 2010/04/21 16:23 UTC
Read the original article Hit count: 210

Filed under:
|
|

I've created a form to update my websites homepage with content but I wanted to know how I could set it up so that a posts title links to a specific post ID. I'd also like to add a Read More link that directs anybody reading the blog to the correct post.

Here is my PHP code:

<html>

<head>
<title>Blog Name</title>
</head>

<body>

<?php
mysql_connect ('localhost', 'root', 'root') ;
mysql_select_db ('tmlblog');

$sql = "SELECT * FROM php_blog ORDER BY timestamp DESC LIMIT 5";

$result = mysql_query($sql) or print ("Can't select entries from table php_blog.<br />" . $sql . "<br />" . mysql_error());
while($row = mysql_fetch_array($result)) {

    $date = date("l F d Y", $row['timestamp']);

    $title = stripslashes($row['title']);
    $entry = stripslashes($row['entry']);
    $password = $row['password'];
    $id = $row['id'];

    if ($password == 1) {
        echo "<p><strong>" . $title . "</strong></p>";

        printf("<p>This is a password protected entry. If you have a password, log in below.</p>");

        printf("<form method=\"post\" action=\"post.php?id=%s\"><p><strong><label for=\"username\">Username:</label></strong><br /><input type=\"text\" name=\"username\" id=\"username\" /></p><p><strong><label for=\"pass\">Password:</label></strong><br /><input type=\"password\" name=\"pass\" id=\"pass\" /></p><p><input type=\"submit\" name=\"submit\" id=\"submit\" value=\"submit\" /></p></form>",$id);
        print "<hr />";
    }
    else { ?>

        <p><strong><?php echo $title; ?></strong><br /><br />
        <?php echo $entry; ?><br /><br />
        Posted on <?php echo $date; ?>

        <hr /></p>

        <?php
    }
} 
   ?>

</body>

</html>

Thanks for any help. I really appreciate any input!

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql