任何帮助将不胜感激
我在关于我的网站之一的 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_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_id
。您所拥有的,无论是否声明并设置了 $parent_id
,查询都会运行;因此出现错误。
关于php - mysql wordpress php 语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18605815/