This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Comment count doesn't work after upgrading to 2.5
#1

I've upgraded to V2.5 (fresh install, not update) and the former code I used to show the comment count doesn't seem to work (and actually crashes the whole script). I get "access denied" message instead of a count and the comments form doesn't even show up (as the first code of comment count is used before the form).

<?php
$id = "34"; //The ID of the page. You can get this from Manage -> Pages.
define('IN_COMMENTICS', '1');
require_once ($_SERVER['DOCUMENT_ROOT'].'comments/includes/db/connect.php');
$query = mysql_query("SELECT * FROM `".$cmtx_mysql_table_prefix."commentics` WHERE is_approved = '1' AND page_id = '$id'");
$total = mysql_num_rows($query);
echo $total;
?>

Tried to delete the define line, but no difference.
Reply
#2

Hi,

There has never been a database table called 'commentics' so that should never have worked. It needs to be changed to 'comments'.

Also change define('IN_COMMENTICS', '1'); to $cmtx_path = '1';
(Normally the $cmtx_path variable is used when including the connect.php file but you're including the file differently, with $_SERVER['DOCUMENT_ROOT'], so you need to set the $cmtx_path variable on another line.)

Also you should be using the MySQLi functions instead of MySQL.

Try this:

PHP Code:
<?php
$id
= "34"; //The ID of the page. You can get this from Manage -> Pages.
$cmtx_path = '1';
require_once (
$_SERVER['DOCUMENT_ROOT'].'comments/includes/db/connect.php');
$query = mysqli_query($cmtx_link, "SELECT * FROM `".$cmtx_mysql_table_prefix."comments` WHERE is_approved = '1' AND page_id = '$id'");
$total = mysqli_num_rows($query);
echo
$total;
?>

Have you completed the interview?
Reply
#3

Damn... stil can't get it work. Reinstalled it and used comments database, then changed the code (actually using a new test page to make sure nothing is interfering). All I use on a new page is:

<?php
session_start();
?>

<?php
$id = "34"; //The ID of the page. You can get this from Manage -> Pages.
$cmtx_path = '1';
require_once ($_SERVER['DOCUMENT_ROOT'].'comments/includes/db/connect.php');
$query = mysqli_query($cmtx_link, "SELECT * FROM `".$cmtx_mysql_table_prefix."comments` WHERE is_approved = '1' AND page_id = '$id'");
$total = mysqli_num_rows($query);
echo $total;
?>
After this is executed I get this error:
Sorry, there is a database problem.</p><p>Please check back shortly. Thanks.
SCREAM: Error suppression ignored for
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\wamp\www\ssi\related\category\related.html on line 27 (the included page where the above code is used for a count view).

and nothing else is loaded afterwards (the actual commentics form).
Reply
#4

Sorry, after thinking about it again, you need to set the $cmtx_path variable properly because connect.php uses that variable to include the other database related files.

PHP Code:
<?php 
$cmtx_path
= $_SERVER['DOCUMENT_ROOT'] . 'comments/';

Have you completed the interview?
Reply
#5

This is working on my setup:

PHP Code:
<?php
$id
= '1'; //The ID of the page. You can get this from Manage -> Pages.
$cmtx_path = 'upload/';
require_once
$cmtx_path . 'includes/db/connect.php';
$query = mysqli_query($cmtx_link, "SELECT * FROM `" . $cmtx_mysql_table_prefix . "comments` WHERE is_approved = '1' AND page_id = '$id'");
$total = mysqli_num_rows($query);
echo
$total;
?>

Have you completed the interview?
Reply
#6

Great Steven, everything works as supposed, EXCEPT - when the count is pulled, it seems that it's shown by the page id (in a comments table), but NOT by the new $cmtx_identifier variable.

Here's an example from myPHPadmin, database "comments", table "pages":

[Image: image.jpg]

I have 4 test pages with comments now, each has that auto-incremental id assigned. IF I write a number from a 1-4 range in that line: "$id = "4"; //The ID of the page. You can get this from Manage -> Pages." , it DOES show the exact number of comments (all good), BUT not of the actual $cmtx_page_id = '48'; which now is replaced with $cmtx_identifier = '48' in the form integration code (and it's NOT the "page_id" anymore from what I understand), it shows the count based that auto-incremental id variable instead. My guess would be that cmtx_identifier change is somehow related with this new issue.
Reply
#7

Yeah the $id variable is meant to be the page ID that's in the URL when you edit a page in Manage -> Pages.

If you want it to be the page identifier instead, then use this:

PHP Code:
<?php
$cmtx_identifier
= '1';
$cmtx_path = 'upload/';
require_once
$cmtx_path . 'includes/db/connect.php';
$cmtx_identifier = mysqli_real_escape_string($cmtx_link, $cmtx_identifier);
$page_query = mysqli_query($cmtx_link, "SELECT `id` FROM `" . $cmtx_mysql_table_prefix . "pages` WHERE `identifier` = '" . $cmtx_identifier . "'");
$page = mysqli_fetch_assoc($page_query);
$id = $page['id'];
$query = mysqli_query($cmtx_link, "SELECT * FROM `" . $cmtx_mysql_table_prefix . "comments` WHERE is_approved = '1' AND page_id = '$id'");
$total = mysqli_num_rows($query);
echo
$total;
?>

Have you completed the interview?
Reply
#8

Seems it's working as supposed now, thank you very much! I'll make sure to support your project as it's a great piece of software and you're a great help Steven.
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by Steven
28-Jan-2023, 01:16 PM
Last Post by Steven
25-Jun-2020, 08:10 AM
Last Post by Steven
21-Oct-2018, 08:42 PM
Last Post by bahar
16-Nov-2015, 10:07 AM
Last Post by Ron
05-Jun-2014, 08:34 PM
Last Post by goppss
08-May-2014, 10:15 PM
Last Post by DjViper
02-Dec-2012, 12:10 PM
Last Post by Static
29-Jan-2011, 10:51 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)