Jump to content

[SOLVED] Need help with my Blog


gaza165

Recommended Posts

Hi all

 

http://www.thedesignmonkeys.co.uk/blog.php

 

Users can acccess the posts by clicking on the title....

 

However, say if I delete that post and someone say has it saved in their favourites or bookmarks

 

it throws an error like this

 

http://www.thedesignmonkeys.co.uk/fullblog.php?id=1

 

this is because there is no such id in the database.... i need some sort of validation to echo an error like

 

"The post you are looking for cannot be found"....link back to the blog

 

Can someone tell me how this can be done.

 

Thanks

 

Garry

Link to comment
https://forums.phpfreaks.com/topic/126660-solved-need-help-with-my-blog/
Share on other sites

<?php
session_start();

include ('dbconnect/dbconnect.php');


$blog_id = mysql_real_escape_string($_GET['id']);

$_SESSION['blog_id'] = $blog_id;

//select the blog based on the id
	$result = mysql_query("SELECT * FROM TABLE WHERE blog.id = '$blog_id'") or die(mysql_error());

	while($row = mysql_fetch_array($result))
		{


		$body = str_replace("’","'",$body);
		$body = str_replace('“','"',$body);
		$body = str_replace('”','"',$body);
		$body = str_replace("\'","'",$body);
		$body = strip_tags($body, "<h1>,<h2>,<h3>,<img>,</img>");	
		$body = htmlentities($row['body']); 

		$blog_date = $row['blog_created'];		
		$blogdate = strtotime($blog_date);
		$blogdate = date(" l F j, Y, g:i a", $blogdate);


			echo "<div id='blogfullwrapper'>";
			echo "<h1>".$row['title']."</h1>";
			echo "<p class='date'>".$blogdate."</p>";

			$blog_title =  $row['title'];

			// Pattern and pregmatches etc \\

			$pattern = "%http://\S+\.(?:jpe?g|png|gif)%i";
			$match = preg_match_all($pattern, $body, $matches,1);
			$gaz = $body;	
			$i = 0;	
				foreach($matches[0] as $url) {	
					$replacement = "%TOKEN".$i."%";	
					$gaz = preg_replace("@$url@", $replacement, $gaz, 1);
					$i++;
				}	

			$vidpattern = "%http://(?:\S+\.swf\b|\S+?youtube\S+)%";
			$vidmatch = preg_match_all($vidpattern, $gaz, $vidmatches);
			$g = 0;	
				foreach($vidmatches[0] as $vidurl) {

					$replace =  '%YOUTUBE'.$g.'%';
					$gaz = preg_replace($vidpattern,$replace, $gaz, 1);
					$g++;
				}

			$linkpattern = "/http:\/\/[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+/i";
			$linkmatch = preg_match_all($linkpattern, $gaz, $linkmatches);
			$c = 0;	
				foreach($linkmatches[0] as $linkurl) {	
					$replacement = "<a href='".$linkurl."'>$linkurl</a>";	
					$gaz = preg_replace("@$linkurl@", $replacement, $gaz, 1);
					$c++;
				}	

			$string = nl2br($gaz);
			$i= 0;

				foreach($matches[0] as $value) {
					$replace = "<img width='60%' height='60%' src='".$value."'></img>";
					$search = "%TOKEN".$i."%";
				    $string = str_replace($search, $replace, $string);
					$i++;
				}

			$e= 0;
				foreach($vidmatches[0] as $vidurl) {	

				$vidurl = substr($vidurl, 31);

					$search = "%YOUTUBE".$e."%";
					$replace = '<embed src="http://www.youtube.com/v/'.$vidurl.'" type="application/x-shockwave-flash" wmode="transparent" width="425" height="350" />';
					$string = str_replace($search, $replace, $string);
					$e++;
				}


			echo "<p class='ajaxblog'>".$string."<p><br/>";
			echo "<a class='back' href='./blog.php'>Back</a>";


			$sql = mysql_query("SELECT * FROM TABLE WHERE blog_id = '$blog_id'");

			echo "<p class='tags'>Tags: <span>";
			while($row = mysql_fetch_array($sql))
			{
			echo $row['tagname'].", ";
			}
			echo "</span></p></div>";





		}


// Select the comments from the db

$sql = mysql_query("SELECT * FROM TABLE WHERE blog_id = '$blog_id' ORDER BY comment_id ASC");
$num = mysql_num_rows($sql);



  echo "<div id='comments'>";	 
  echo "<h2>".$num." Response(s) to ". $blog_title ."</h2>";
  
  
				$match = preg_match_all($pattern, $body, $matches,1);


				$gaz = $body;
				$i = 0;

				foreach($matches[0] as $url){	
					$replacement = "%TOKEN".$i."%";	
					$gaz = preg_replace("@$url@", $replacement, $gaz, 1);
					$i++;
				}


				$string = nl2br(htmlentities($gaz));
				$i= 0;

				foreach($matches[0] as $value) {


					$replace = "<img src='".$value."'>";

					$search = "%TOKEN".$i."%";

				    $string = str_replace($search, $replace, $string);


				$i++;

				}

	while($row1 = mysql_fetch_array($sql))
		{		

		$username = $row1['username'];



			$profile_picture = mysql_query("SELECT * FROM TABLE WHERE username = '$username'");



		$comments = $row1['comments'];
		$comments = strip_tags($comments,"<br/><br>");
		$comments = htmlentities($row1['comments']);
		$date = $row1['date_posted'];
		$date = strtotime($date);
		$date = date(" l F j, Y, g:i a", $date);

		$match = preg_match_all($pattern, $comments, $cmatches,1);


				$c = 0;

				foreach($cmatches[0] as $curl){	
					$creplacement = "%TOKEN".$c."%";	
					$comments = preg_replace("@$curl@", $creplacement, $comments, 1);
					$c++;
				}
				$cstring = nl2br($comments);

			$linkpattern = "/http:\/\/[A-Za-z0-9\-_]+\\.+[A-Za-z0-9\.\/%&=\?\-_]+/i";
			$linkmatch = preg_match_all($linkpattern, $cstring, $linkmatches);
			$d = 0;	
				foreach($linkmatches[0] as $linkurl) {	
					$replacement = "%LINK".$d."%";	
					$cstring = preg_replace("@$linkurl@", $replacement, $cstring, 1);
					$d++;
				}

				$c= 0;

				foreach($cmatches[0] as $cvalue) {
					$creplace = "<img width='25%' style='padding-bottom: 20px; text-align: left' height='25%' src='".$cvalue."'>";
					$csearch = "%TOKEN".$c."%";
				    $cstring = str_replace($csearch, $creplace, $cstring);	
					$c++;	
				}

				$c= 0;
				foreach($linkmatches[0] as $linkurl) {	
					$search = "%LINK".$c."%";
					$replace = "<a href='".$linkurl."'>$linkurl</a>";	
					$cstring = str_replace($search, $replace, $cstring);
					$c++;
				}

				$cstring = str_replace("\'","'",$cstring);
				$cstring = str_replace("’","'",$cstring);
				$cstring = str_replace('“','"',$cstring);
				$cstring = str_replace('”','"',$cstring);
				$cstring = str_replace('\"','"',$cstring);
				$cstring = str_replace('\"','"',$cstring);
				$cstring = str_replace('','<img class="emotion" src="img/blog/emoticons/smile.png" width="15px" height="15px">',$cstring);
				$cstring = str_replace('','<img class="emotion" src="img/blog/emoticons/sad.png" width="15px" height="15px">',$cstring);
				$cstring = str_replace('','<img class="emotion" src="img/blog/emoticons/bigsmile.png" width="15px" height="15px">',$cstring);
				$cstring = str_replace(':x','<img class="emotion" src="img/blog/emoticons/angry.png" width="15px" height="15px">',$cstring);

		echo "<a name='showcomments'>";
		echo "<div id='commentwrapper'>";
		while($pic = mysql_fetch_array($profile_picture)){		
		echo "<div id='profilepicwrapper'><img height='100%' width='100%' src='".$pic['profile_picture']."'></div>";
		}
		echo "<h4>".htmlentities(nl2br($row1['name']))."</h4><p>(".$row1['username'].") Says: </p>";
		echo "<p class='date'>".$date."</p>";
		echo "<p class='comment'>".$cstring."</p>";			
		echo "</div>";
		echo "</a>";

		}
  echo "</div>";
  



?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.