Error with wpdb::prepare
-
On this page:
options-general.php?page=cjtoolboxthere is a PHP error showing twice within each block. See screenshot.The error is:
Warning: Missing argument 2 for wpdb::prepare(), called in <em>[removed]</em>/wp-content/plugins/css-javascript-toolbox/css-js-toolbox.php on line 895 and defined in <em>[removed]</em>/wp-includes/wp-db.php on line 990From the source:
/** * Get code template selection list. * * @param string Type of template. It could be 'css' or 'js'; * @param string Unique identified for the block list. * @return void */ function show_dropdown_box($type, $boxid) { global $wpdb; $query = $wpdb->prepare("SELECT id, title FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type = '{$type}'"); $list = $wpdb->get_results($query); if(count($list)) { echo '<select id="cjtoolbox-'.$type.'-'.$boxid.'" class="cjtoolbox-'.$type.'">'; foreach($list as $def) { echo '<option value="' . $def->id . '">'. $def->title . '</option>'; } echo '</select>'; } }The line is:
$query = $wpdb->prepare("SELECT id, title FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type = '{$type}'");My proposed solution:
$query = $wpdb->prepare("SELECT id, title FROM {$wpdb->prefix}cjtoolbox_cjdata WHERE type = %s", $type);Let me know what you think.
The topic ‘Error with wpdb::prepare’ is closed to new replies.