<?php $connect = mysql_connect('localhost', 'root', 'root'); $databse = mysql_select_db(blog, $connect); echo mysql_error(); function valid_pid($pid) { $pid = (int)$pid; $total = mysql_query("SELECT COUNT(post_id) FROM posts WHERE post_id='$pid'"); $total = mysql_result($total, 0); if ($total !=1) { return false; } else { return else; } } function get_posts() { $sql = "SELECT posts.post_id AS id, posts.post_title AS title, LEFT(posts.post_body, 512) AS preview, posts.post_user AS user, DATE_FORMAT(posts.post_date, '%d/%m/%y %H:%i:%s') AS date, comments.total_comments, DATE_FORMAT(comments.last_comment, '%d/%m/%y %H:%i:%s') AS last_comment, FROM posts LEFT JOIN ( SELECT post_id, COUNT(comment_id) AS total_comments, MAX(comment_date) AS last_comment, FROM comments GROUP BY post_id ) AS comments ON posts.post_id = comments.post_id ORDER BY posts.post_date DESC"; echo mysql_error(); $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' => (), 'last_comment' => () ); } } function get_post($pid) { } function add_post($name, $title, $body) { } echo 'Hello'; ?>
Php Blog
Php Blog
Hello i have some code i copied from the php blog tutorial that is not working. Any help is accepted.
Last edited by jacek on Fri Dec 16, 2011 11:38 am, edited 1 time in total.
Reason: removed email address
Reason: removed email address
Re: Php Blog
i see you didn`t use backtics at all?
the functions get_post, add_post are not defined yet?
and what is your error message/s or what is not working exactly?
the functions get_post, add_post are not defined yet?
and what is your error message/s or what is not working exactly?
$sql = "SELECT `posts`.`post_id` AS `id`, `posts`.`post_title` AS `title`, `posts`.`post_video` AS `video`, ...
Re: Php Blog
this is the error
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM posts LEFT JOIN ( SELECT ' at line 9
Re: Php Blog
If you look just before the part of the SQL that it quotes in the error, in this case "FROM users" the problem is usually there. On the line above the FROM, you have a comma at the end that should not be there since it's the list item in the list.
Re: Php Blog
thank you that is working now it turns out i did that twice in that same query now i know to look for and now i am able to watch the rest of the video. Thanks again
Jason
Jason
Re: Php Blog
ok so that is working but now i have this code giving me an error the comments.func.inc.php
<?php function get_comments($pid) { $pid = (int)$pid; $sql = "SELECT comment_body AS body, comment_user AS user, DATE_FROMAT(comment_date, '%d/%m/%Y %H:%i:%s') AS date FROM comments WHERE post_id='$pid'"; $result = mysql_query($sql); $comments = array(); while (($row = mysql_fetch_assoc($result)) !===false) { $comments[] = $row; } return $comments; } function add_comment($pid, $user, $body) { if (valid_pid($pid) === false) { return false; } $pid = (int)$pid; $user = mysql_real_escape_string(htmlentities($user)); $body = mysql_real_escape_string(nl2br(htmlentities($body))); mysql_query("INSERT INTO comments (post_id, comment_user, comment_body, comment_date) VALUES ('$pid', '$user', '$body', NOW())"); return true; } echo 'x'; ?>
Re: Php Blog
what is the error message?
Re: Php Blog
eh? you should turn "error_reporting(E_ALL);" on.
btw. i found the error in line 16 you have one "=" to much..
btw. i found the error in line 16 you have one "=" to much..
Re: Php Blog
ok thank you that was the error
Re: Php Blog
Ok. now I am having a problem with the mysql
NOW()function here is the query code
$sql = "INSERT INTO blog_posts (post_title, post_body, post_user, post_date, post_keywords, post_des) VALUES ('$title', '$body', 'Jason', 'NOW()', '$keywords', '$des')"; $add_post = mysql_query($sql);
-
- Posts: 534
- Joined: Thu May 05, 2011 8:19 pm
Re: Php Blog
And what exactly is the problem your having?
I don't like to brag, but I wasn't circumcised. I was circumnavigated.
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Want to learn something new? Or maybe reinforce what you already know? Or just help out? Please subscribe to my videos: http://goo.gl/58pN9
Re: Php Blog
mmmh...can you please tell the exact problem and the error message! so we have an idea what we should look for, from the beginning!
if you dont get any error messages, use "error_reporting(E_ALL);" at the top of your page, or set it in your php.ini to:
"; error_reporting
; Default Value: E_ALL & ~E_NOTICE"
..so it will be always enabled, as it normaly should be.
if you dont get any error messages, use "error_reporting(E_ALL);" at the top of your page, or set it in your php.ini to:
"; error_reporting
; Default Value: E_ALL & ~E_NOTICE"
..so it will be always enabled, as it normaly should be.
Re: Php Blog
it is inserting 0/0/0000 00:00:00 always