mysql wordpress php语法错误

mysql wordpress php语法错误,php,mysql,syntax,Php,Mysql,Syntax,任何帮助都将不胜感激 我在关于我的一个站点的php错误日志中得到了这个错误。事实上,我有另一个网站与完全相同的设置,但没有错误 我真的迷路了 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 que

任何帮助都将不胜感激

我在关于我的一个站点的php错误日志中得到了这个错误。事实上,我有另一个网站与完全相同的设置,但没有错误

我真的迷路了

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')
这是我的代码

<?
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!="")
{
?>

$parent\u id
为空。您可以通过以下方式解决此问题:

$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 }

这确保在调用查询之前设置了
$parent\u id
。如果声明并设置了
$parent\u id
,查询将运行;因此出现了错误。

您的问题是,
$parent\u id
是转换为空字符串的东西。