MySQL查询错误我有这样的代码:在WordPress
add_action('delete_post', 'my_delete_function');
function my_delete_function($post_id) {
global $wpdb;
$achievement = get_the_category($post_id);
$h = $achievement[0]->cat_ID;
$s = ''.str_replace('"', '', $h);
$p = var_dump(htmlentities($s));
$wpdb->query("INSERT INTO ".$wpdb->prefix."votes (post, votes, guests, usersinks, guestsinks) VALUES('', ".$p.", '', '', '') ") or die(mysql_error());
}
MySQL总是抛出此错误
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
伊夫跑在phpMyAdmin相同的查询,取代了PHP和值VAR和它工作正常
另外,通过在空白页上使用echo函数,我确信$ s的值只是一个数字。
任何帮助表示赞赏
在最后一行之前添加一个'var_dump($ s);'来检查你输出的内容。如果它包含HTML,请使用'var_dump(htmlentities($ s));' – 2012-01-08 11:39:36
您能显示完整的最终查询吗? – 2012-01-08 11:41:32
检查您的单引号实际上是单引号而不是反引号。还要替换$ s。与。(int)$ s。只想确认一下。 – 2012-01-08 11:42:15