0

Any help will be greatly appreciated

I get this error in my php error logs regarding one of my sites. I actually have another site with exactly the same setup but no errors....

I'm really lost on this one

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 '' at line 1 for query SELECT *  FROM  wp_cat_banners where cat_id= made by require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'), include('/themes/telegraph-wp-3-1/single.php'), get_header, locate_template, load_template, require_once('/themes/telegraph-wp-3-1/header.php')

This is my code....

<?
global $wpdb;
$cat_ID = get_query_var('cat');
if($cat_ID!="")
{
$parent_id=get_top_parent_category((int) $cat_ID);
}
$sql2 = "SELECT *  FROM  wp_cat_banners where cat_id=$parent_id";
$cc=$wpdb->get_row($sql2, 'ARRAY_A');
$background=$cc['Background_image'];
if($background !="")
{
?>


<?
global $wpdb;
if(is_front_page() || is_page())
{
$sql2 = "SELECT *  FROM  wp_cat_banners_home where Id=1";
$cc=$wpdb->get_row($sql2, 'ARRAY_A');
$right_banner5=$cc['Right_banner5'];
if($right_banner5!="")
{
?>
<div id="bannerHead1"><?php echo $right_banner5; ?></div>
<?php
}
}
else
{
if(is_single())
{
$categories= get_the_category(); 
$cat_ID=$categories[0]->cat_ID;
}
else
{
$cat_ID = get_query_var('cat');
}
if($cat_ID!="")
{
$parent_id=get_top_parent_category((int) $cat_ID);
$sql2 = "SELECT *  FROM  wp_cat_banners where cat_id=$parent_id";
$cc=$wpdb->get_row($sql2, 'ARRAY_A');
$right_banner5=$cc['Right_banner5'];
if($right_banner5!="")
{
?>
1
  • Your problem is that $parent_id is something that converts to an empty string. Commented Sep 4, 2013 at 5:11

1 Answer 1

1

$parent_id is empty. You can fix this by:

$cat_ID = get_query_var('cat');
if($cat_ID!="")
{
    $parent_id=get_top_parent_category((int) $cat_ID);
    $sql2 = "SELECT *  FROM  wp_cat_banners where cat_id=$parent_id";
}
else { //else code here }

This makes sure that $parent_id is set before calling the query. What you had, the query would run regardless if $parent_id is declared and set; thus the error.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.