Blog(including commenting) issue
Posted: Sat Jan 12, 2013 10:03 pm
Hi, I am receiving the following errors when trying to test my blog_list page:
Notice: Undefined variable: sql in C:\xampp\htdocs\caddingtoncc\blog\core\inc\posts.inc.php on line 36
Notice: Undefined variable: sql in C:\xampp\htdocs\caddingtoncc\blog\core\inc\posts.inc.php on line 38
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\caddingtoncc\blog\core\inc\posts.inc.php on line 41
Here is the php syntax from the posts.inc.php file
Could you please help.
Many thanks,
Gary
Notice: Undefined variable: sql in C:\xampp\htdocs\caddingtoncc\blog\core\inc\posts.inc.php on line 36
Notice: Undefined variable: sql in C:\xampp\htdocs\caddingtoncc\blog\core\inc\posts.inc.php on line 38
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\caddingtoncc\blog\core\inc\posts.inc.php on line 41
Here is the php syntax from the posts.inc.php file
<?php // checks if the given post id is in the table function valid_pid($pid){ $pid = (int)$pid; $total = mysql_query("select count('post_id') from 'post' where 'post_id' = {$pid}"); $total = mysql_result($total, 0); if ($total !=1){ return false; }else{ return true; } } // fetches a summary of all the blog posts function get_posts(){ $sql-"select `post`.`post_id` as `id`, `post`.`post_title` as `title`, left(`post`.`post_body`, 512) as `preview`, `post`.`post_user` as `user`, date_format(`post`.`post_date`, `%d/%m/%Y %h:%i:%s`) as `date`, `comment`.`total_comments`, date_format(`comment`.`last_comment`, `%d/%m/%Y %h:%i:%s`) as `last comment` from `post` left join ( SELECT `post_id`, count(`comment_id`) as `total_comments`, max(`comment_date`) as `last_comment` from `comment` group by `post_id` ) as `comment` on `post`.`post_id` = `comment`.`post_id` order by `post`.`post_date` desc"; $posts = mysql_query($sql); $rows = array(); while (($row = mysql_fetch_assoc($posts)) !==false){ $rows[] = array( 'id' => $row['id'], 'title' => $row['title'], 'preview'=> $row['preview'], 'user' => $row['user'], 'date' => $row['date'], 'total_comments' => ($row['total_comments'] === null) ? 0 : $row['total_comments'], 'last_comment' => ($row['last_comment'] === null) ? 'never' : $row['last_comment'] ); } return $rows; } // fetches a single post from the table function get_post($pid){ $pid = (int)$pid; $sql = "select `post_title` as `title`, `post_body` as `body`, `post_user` as `user`, `post_date` as `date` from `post` where `post_id` = {$pid}"; $post = mysql_query($sql); $post = mysql_fetch_assoc($post); $post['comments'] = get_comments($pid); return $post; } // adds a new blog entry function add_post($name, $title, $body){ $name = mysql_real_escape_string(htmlentities($name)); $title = mysql_real_escape_string(htmlentities($title)); $body = mysql_real_escape_string(nl2br(htmlentities($body))); mysql_query("insert into `post` (`post_user`, `post_title`, `post_body`, `post_date`) values ('{$name}','{$title}','{$body}',now())"); } ?>I have run the query in the database and it is returning the data that I have entered.
Could you please help.
Many thanks,
Gary