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