Page 1 of 1

Help needed with the "add_comment" function in the blog tut.

Posted: Fri Jul 29, 2011 8:32 am
by nyo
Hi,

I am working on the add_comment function and I have a slight issue I don't know how to solve. Here is the function I want to use:
function add_comment($name, $author, $email, $body) {
	if(valid_post($name) == false){
		return false;
	}
	$name = mysql_real_escape_string(htmlentities($name));
	$author = mysql_real_escape_string(htmlentities($author));
	$email	= mysql_real_escape_string(htmlentities($email));
	$body = mysql_real_escape_string(nl2br(htmlentities($body)));
	mysql_query("INSERT INTO `comments` (`com_post_id`, `com_author`, `com_author_email`, `com_body`, `com_date`) VALUES ('$name', '$author', '$email', '$body', NOW())");
	return true;
}
I am getting the post by its name and not the id. I need to match `com_post_id` with the `posts`.`id` but I have $name (`post_name`) available. I checked WordPress to see how the commenting is handled but it looks too complicated. The reason I am getting posts by $name is that I want nice looking urls such as http://www.mysite.com/this-is-a-post, and here post_name = this-is-a-post.

Re: Help needed with the "add_comment" function in the blog

Posted: Fri Jul 29, 2011 2:13 pm
by jacek
It might be easier to still work with ids, you could have the url as http://www.mysite.com/8/this-is-a-post

Where 8 is the post id and the name is just there for decoration.