I've managed to set up my links so that they run to the url I want. Originally they were running to 'myweb.com/blog/1/title' but i've decided that's not quite good enough and want to remove the article id from the url so it reads 'myweb.com/blog/title'. I understand I need to get the blog reading from the $title row and not the $id but I'm not quite sure how to do this with my code, which is this:
PHP Code:
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
die("Invalid ID specified.");
}
$id = (int)$_GET['id'];
$sql = "SELECT * FROM php_blog WHERE id='$id' LIMIT 1";
$result = mysql_query($sql) or print ("Can't select entry 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'];
$get_categories = mysql_query("SELECT * FROM php_blog_categories WHERE `category_id` = $row[category]");
$category = mysql_fetch_array($get_categories);
if ($password == 1) {
if (isset($_POST['username']) && $_POST['username'] == $my_username) {
if (isset($_POST['pass']) && $_POST['pass'] == $my_password) {
?>
<p><strong><?php echo $title; ?></strong><br /><br />
<?php echo $entry; ?><br /><br />
Posted in <?php echo $category['category_name']; ?> on <?php echo $date; ?></p>
<?php
}
else { ?>
<p>Sorry, wrong password.</p>
<?php
}
}
else {
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=\"blog_single.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 "<br /><br />";
}
}
else { ?>
I'm open to suggestion on ways to do this btw, having the blog call the title instead of the id is the only way I've read to do it so far.
At the moment, to achieve 'myweb.com/blog/article-title/' i have this in my .htaccess
Quote:
|
RewriteRule ^blog/([^/\.]+)/?$ blog_single.php?title=$1 [L]
|
This at the moment however doesn't allow the page to call from the
database
as the code is looking for the ID.
When i had 'myweb.com/blog/1/article-title' I had this is my .htaccess:
Quote:
RewriteRule ^blog/([^/\.]+)/?/([^/\.]+)/?$ blog_single.php?id=$1&title=$2 [L]
And that called from the database fine.
|
------------------
Any help would be gratefully appreciated, thank you in advance.