我一直在浏览 WordPress Codex,似乎我的语法是正确的,但我似乎无法追查为什么我在errors.text
与下面代码相关的文件中不断出现一行一行的错误,这是为了WordPress 简码:
function blahblah_display_referrer() {
global $wpdb, $user_ID;
// Logged in user
if ( is_user_logged_in() == true ) {
$sql = "SELECT display_name FROM " .$wpdb->prefix. "users WHERE ID=".$user_ID;
$ref = $wpdb->get_var($wpdb->prepare($sql));
return 'Welcome Back: '.$ref;
}
// Visitor message with cookie or without...
$ref = $_COOKIE['ref'];
$sql = "SELECT display_name FROM " .$wpdb->prefix. "users WHERE ID=".$ref;
$ref = $wpdb->get_var($wpdb->prepare($sql));
if ( !isset($ref) ) {
return 'Welcome Visitor';
}
return 'Referred By: '.$ref;
}
正如我之前所说,这段代码可以完美执行,没有任何问题。它只显示以下错误:
[10-Jul-2012 15:10:45] 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 display_name FROM wp_users WHERE ID= made by
require('wp-blog-header.php'), require_once('wp-includes/template-loader.php'),
include('/themes/kaboodle/index.php'), get_sidebar, locate_template, load_template,
require_once('/themes/kaboodle/sidebar.php'), woo_sidebar, dynamic_sidebar,
call_user_func_array, WP_Widget->display_callback, WP_Widget_Text->widget,
apply_filters('widget_text'), call_user_func_array, do_shortcode, preg_replace_callback,
do_shortcode_tag, call_user_func, blahblah_display_referrer
这是我的服务器信息:
Apache version 2.2.21
PHP version 5.2.17
MySQL version 5.1.63-cll
Architecture x86_64
Operating system linux