WordPress.org

Ready to get started?Download WordPress

Forums

Database Comment_Approved Error (19 posts)

  1. intricateartist
    Member
    Posted 9 years ago #

    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!

  2. Mark (podz)
    Support Maven
    Posted 9 years ago #

    What plugins do you have ?

  3. intricateartist
    Member
    Posted 9 years ago #

    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.

  4. markb
    Member
    Posted 9 years ago #

    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

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

  6. markb
    Member
    Posted 9 years ago #

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

  7. "><?php the_title(); ?>
  8. <?php endforeach; ?>

  • markb
    Member
    Posted 9 years ago #

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

  • "><?php the_title(); ?>
  • <?php endforeach; ?>

    **sorry removed the link **

  • MacManX (James Huff)
    Volunteer Pyromancer & Mod
    Posted 9 years ago #

    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
    Member
    Posted 9 years ago #


    $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
    Member
    Posted 9 years ago #

    i never added it as a 'plugin' as such, i just added the include... so the plug in doesn't show up..

  • MacManX (James Huff)
    Volunteer Pyromancer & Mod
    Posted 9 years ago #

    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
    Member
    Posted 9 years ago #

    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
    Member
    Posted 9 years ago #

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

  • MacManX (James Huff)
    Volunteer Pyromancer & Mod
    Posted 9 years ago #

    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
    Member
    Posted 9 years ago #

    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
    Member
    Posted 9 years ago #

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

  • freedomblue
    Member
    Posted 9 years ago #

    i get the same sql error on a fresh install on xampp

  • freedomblue
    Member
    Posted 9 years ago #

    *bump*

  • kashirat
    Member
    Posted 8 years ago #

    Apparently get_posts overwrites the $posts variable.

    If you surround your sidebar code with

    $store_posts = $posts;
    //<print top 5 listsings...'

    $posts = $store_posts

    That should do it.

  • Topic Closed

    This topic has been closed to new replies.

    About this Topic

    Tags