• 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)
  • What plugins do you have ?

    Thread Starter intricateartist

    (@intricateartist)

    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.

    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

    (@macmanx)

    Volunteer Moderator

    Both of you, can you reproduce the error disabling all of your plugins?

    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) :
    ?>

    $posts = get_posts(‘numberposts=5&offset=1&category=1’);
    foreach($posts as $post) :
    ?>

    Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    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.


    $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; ?>

    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

    (@macmanx)

    Volunteer Moderator

    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?

    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??

    that seems to work.. my posts now display.. what does that mean?

    Moderator James Huff

    (@macmanx)

    Volunteer Moderator

    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.

    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??

    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)
  • The topic ‘Database Comment_Approved Error’ is closed to new replies.