Title: Database Comment_Approved Error
Last modified: August 18, 2016

---

# Database Comment_Approved Error

 *  [intricateartist](https://wordpress.org/support/users/intricateartist/)
 * (@intricateartist)
 * [20 years, 9 months ago](https://wordpress.org/support/topic/database-comment_approved-error/)
 * On post paging, archives etc, there are sporadic “entries” in my blog that appear
   as WordPress Database Errors.
 * The post container reads:
 * WordPress Database Error: [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‘
   AND comment_approved = ‘1″ at line 1] SELECT COUNT(comment ID) FROM wp_comments
   WHERE comment_post_ID = AND comment_approved = ‘1’;
 * I just noticed this error yesterday. I did upgrade to 1.5.1.3 last week (replaced
   necessary files after backing up same files). I’m no database programmer but 
   I know how to get in there and make adjustments to lines (with help). Can anyone
   help me with this?
 * Thanks in advance!

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/database-comment_approved-error/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/database-comment_approved-error/page/2/?output_format=md)

 *  [Mark (podz)](https://wordpress.org/support/users/podz/)
 * (@podz)
 * [20 years, 9 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232196)
 * What plugins do you have ?
 *  Thread Starter [intricateartist](https://wordpress.org/support/users/intricateartist/)
 * (@intricateartist)
 * [20 years, 9 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232211)
 * I am using Spam Karma 2.0 (beta), moderate pingbacks, moderate trackbacks, subscribe
   to comments, theme switcher, useronline, weather icon, wp grins and wp paginate.
 *  [markb](https://wordpress.org/support/users/markb/)
 * (@markb)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232358)
 * I have the same problem!! 🙁
 * I had just added an include that gets the recent posts… all of a sudden, every
   post on my site now says:
 * WordPress database error: [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‘
   AND comment_approved = ‘1” at line 1]
    SELECT COUNT(comment_ID) FROM yl_comments
   WHERE comment_post_ID = AND comment_approved = ‘1’;
 * I’d appreciate help as soon as possible.. regards
 *  Moderator [James Huff](https://wordpress.org/support/users/macmanx/)
 * (@macmanx)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232359)
 * Both of you, can you reproduce the error disabling all of your plugins?
 *  [markb](https://wordpress.org/support/users/markb/)
 * (@markb)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232360)
 * i’ve removed the include but the problem remains… 🙁 i’m thinking maybe it made
   a change 2 the db and even once removed it still makes problems?? the include
   is as follows:
 * <?php
    $posts = get_posts(‘numberposts=5&offset=1&category=1’); foreach($posts
   as $post) : ?>
    - 
    - <?php endforeach; ?>
 *  [markb](https://wordpress.org/support/users/markb/)
 * (@markb)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232361)
 * $posts = get_posts(‘numberposts=5&offset=1&category=1’);
    foreach($posts as $
   post) : ?>
    - 
    - <?php endforeach; ?>
    - **sorry removed the link **
 *  Moderator [James Huff](https://wordpress.org/support/users/macmanx/)
 * (@macmanx)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232362)
 * Yes, you may have removed the include, but did you also disable the plugin via
   the Plugins interface? And, please post your code inside backticks. The backtick
   key is typically found below the escape key, to the left of the one key, and 
   above the tab key.
 *  [markb](https://wordpress.org/support/users/markb/)
 * (@markb)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232363)
 * `
    $posts = get_posts('numberposts=5&offset=1&category=1'); foreach($posts as
   $post) : ?> <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
   </li> <?php endforeach; ?>
 *  [markb](https://wordpress.org/support/users/markb/)
 * (@markb)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232364)
 * i never added it as a ‘plugin’ as such, i just added the include… so the plug
   in doesn’t show up..
 *  Moderator [James Huff](https://wordpress.org/support/users/macmanx/)
 * (@macmanx)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232365)
 * Ah, sorry for the misunderstanding. Try switching to the WordPress Default Theme(
   or the WordPress Classic Theme if you are already on the Default Theme). Does
   the error still occur?
 *  [markb](https://wordpress.org/support/users/markb/)
 * (@markb)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232366)
 * the error message i get on my actual blog seems to point to this line of code:
 * `
    $comments = $wpdb->get_results("SELECT * FROM $wpdb->comments WHERE comment_post_ID
   = $id AND comment_approved = '1' ORDER BY comment_date");
 * is that line as it should be??
 *  [markb](https://wordpress.org/support/users/markb/)
 * (@markb)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232367)
 * that seems to work.. my posts now display.. what does that mean?
 *  Moderator [James Huff](https://wordpress.org/support/users/macmanx/)
 * (@macmanx)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232368)
 * That means that there’s still something that shouldn’t be there in whatever file
   you added the “gets the recent posts” include to. Your best plan of action would
   be to download WordPress again, and replace that file on your server with a fresh
   copy from the new download, or replace it with a backup copy from a time before
   you added the “gets the recent posts” include.
 *  [markb](https://wordpress.org/support/users/markb/)
 * (@markb)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232369)
 * nevermind.. i switched to classic and then back to my theme and it cleared the
   problem.. (whatever it was)
 * it seemed to happen after i put in the ‘recent comments’ include…
 * do you know of an include that works well for this?? do i actually have to install
   it or is it just a matter of pasting in the include??
 *  [roterhund](https://wordpress.org/support/users/roterhund/)
 * (@roterhund)
 * [20 years, 8 months ago](https://wordpress.org/support/topic/database-comment_approved-error/#post-232381)
 * I have the same problem, but it doesn’t go away when I switch themes. I don’t
   have any plugins activated either.
 * I have a file I called Â»navigation.phpÂ« that’s included in the index.php. In
   the navigation.php I have two lists of posts in certain categories (2 and 3) 
   and that’s what’s causing the problem (I think, because when I cut the code the
   problem disappears):
    `<ul> <?php $posts = get_posts('numberposts=10&category
   =2'); foreach($posts as $post) : ?> <li><a href="<?php the_permalink(); ?>"><?
   php the_title(); ?></a></li> <?php endforeach; ?> </ul>
 * I’m wondering why in the output error-code there’s no value assigned to comment_post_ID:
   `
   SELECT COUNT(comment_ID) FROM mt_comments WHERE comment_post_ID = AND comment_approved
   = '1';`
 * Any help/ideas => much love and thanks! 🙂

Viewing 15 replies - 1 through 15 (of 18 total)

1 [2](https://wordpress.org/support/topic/database-comment_approved-error/page/2/?output_format=md)
[→](https://wordpress.org/support/topic/database-comment_approved-error/page/2/?output_format=md)

The topic ‘Database Comment_Approved Error’ is closed to new replies.

## Tags

 * [database](https://wordpress.org/support/topic-tag/database/)
 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 18 replies
 * 7 participants
 * Last reply from: [kashirat](https://wordpress.org/support/users/kashirat/)
 * Last activity: [20 years, 3 months ago](https://wordpress.org/support/topic/database-comment_approved-error/page/2/#post-232466)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
