Support » Plugin: Category Icons » Missing Argument 2 for wpdb::prepare

Viewing 15 replies - 16 through 30 (of 31 total)
  • Tnaks a lot Tadesse for your code

    ( you miss a “}” at the end of your change on bm_caticons_adminicons function ? )

    arf ๐Ÿ™ u have another error in admin page of this plugin :

    Warning: Missing argument 2 for wpdb::prepare(), called in /homepages/2/d142305709/htdocs/als/wp-content/plugins/category-icons/category_icons.php on line 1337

    Hello Davs63,
    well, yes } is missing ..
    this whole modified function copied here:

    /**
     * Display the icons panel in Icons tab
     * @author Brahim MACHKOURI
     */
    // I took some of the code from categories.php of WordPress 2.5 and modified it a little
    function bm_caticons_adminicons() {
    	global $wpdb;
    	$action = isset($_REQUEST['action']) ? $_REQUEST['action'] : '';
    	if ( isset($_GET['deleteit']) && isset($_GET['delete']) )
    		$action = 'bulk-delete';
    	switch($action) {
    		case 'update-category-icon':
    			$cat_ID = (int) $_GET['cat_ID'];
    			$priority = $_REQUEST['ig_priority'];
    			$icon = $_REQUEST['ig_icon'];
    			$small_icon = $_REQUEST['ig_small_icon'];
    			if ( $wpdb->get_var( $wpdb->prepare( "SELECT cat_id FROM $wpdb->ig_caticons WHERE cat_id = '%d' ", $cat_ID ) ) ) {
    				$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->ig_caticons SET priority = '%d', icon = '%s', small_icon='$s' WHERE cat_id = '%d' ", $priority, $icon, $small_icon, $cat_ID ) ) ;
    			} else {
    				$wpdb->query($wpdb->prepare("INSERT INTO $wpdb->ig_caticons (cat_id, priority, icon, small_icon) VALUES ('$cat_ID', '$priority', '$icon', '$small_icon')"));
    			}
    		break;
    		case 'delete':
    			$cat_ID = (int) $_GET['cat_ID'];
    			if (!is_admin() || !current_user_can( 'manage_categories' ))
    				wp_die(__('Are you trying to cheat ?','category_icons'));
    			$cat_name = get_catname($cat_ID);
    			$request = "DELETE FROM $wpdb->ig_caticons WHERE cat_id='$cat_ID'";
    			if (false === $wpdb->query($wpdb->prepare($request) ))
    				wp_die(__('Error in Category Icons','category_icons').' : '.$request);
    		break;
    		case 'bulk-delete':
    			if (!is_admin() || !current_user_can( 'manage_categories' ))
    				wp_die( __('You are not allowed to delete category icons.','category_icons') );
    			foreach ( (array) $_GET['delete'] as $cat_ID ) {
    				$cat_name = get_catname($cat_ID);
    				$wpdb->query($wpdb->prepare("DELETE FROM $wpdb->ig_caticons WHERE cat_id='$cat_ID'"));
    			}
    		break;
    	}
    	switch ($action) {
    	case 'edit':
    		$cat_ID = (int) $_GET['cat_ID'];
    		$category = get_category_to_edit($cat_ID);
    		list($priority, $icon, $small_icon) = bm_caticons_get_icons($cat_ID);
    		?>
    		<div class="wrap">
    		<h2><?php _e('Select Category Icons','category_icons') ?></h2>
    		<form method="post" name="caticons-form1" action="">
    		  <?php wp_nonce_field('caticons-nonce'); ?>
    			<input type="hidden" name="ig_module" value="caticons" />
    			<input type="hidden" name="ig_tab" value="icons" />
    			<input type="hidden" name="action" value="update-category-icon" />
                <table  border="0" class="form-table">
                    <tr>
                        <th scope="row" style="vertical-align:text-top;"><?php _e('Category ID','category_icons'); ?></th>
                        <td colspan="2" ><?php echo $cat_ID;?></td>
                    </tr>
                    <tr>
                        <th scope="row" style="vertical-align:text-top;"><?php _e('Name','category_icons'); ?></th>
                        <td colspan="2"><?php echo $category->name;?></td>
                    </tr>
                    <tr>
                        <th scope="row" class="num" style="vertical-align:text-top;"><?php _e('Priority','category_icons'); ?></th>
                        <td colspan="2">
                            <input type="text" name="ig_priority" size="5" value="<?php echo $priority; ?>" />
                        </td>
                    </tr>
                    <tr>
                        <th scope="row" style="vertical-align:text-top;"><?php _e('Icon','category_icons'); ?></th>
                        <td valign="top"><label><?php _e('Select a file : ','category_icons');?></label>
                            <select name="ig_icon" onchange="icon_preview.src=('<?php echo ig_caticons_url();?>/'+this.options[this.selectedIndex].value);">
                                <option value="">--- <?php _e('No Icon','category_icons'); ?> ---</option>
                                <?php bm_caticons_get_icons_paths($icon);	?>
                            </select><br />
                            <label><?php _e('Or enter an URL : ','category_icons');?><input type="text" name="bm_icon_url"/></label>
                        </td>
                        <td valign="top"><img id="icon_preview" src="<?php echo ig_caticons_url()."/$icon";?>" alt="icon" /></td>
                    </tr>
                    <tr>
                        <th scope="row" style="vertical-align:text-top;"><?php _e('Small Icon','category_icons'); ?></th>
                        <td valign="top"><label><?php _e('Select a file : ','category_icons');?></label>
                            <select name="ig_small_icon" onchange="small_icon_preview.src=('<?php echo ig_caticons_url();?>/'+this.options[this.selectedIndex].value);">
                                <option value="">--- <?php _e('No Icon','category_icons'); ?> ---</option>
                                <?php bm_caticons_get_icons_paths($small_icon); ?>
                            </select><br />
                            <label><?php _e('Or enter an URL : ','category_icons');?><input type="text" name="bm_smallicon_url"/></label>
                        </td>
                        <td valign="top"><img id="small_icon_preview" src="<?php echo ig_caticons_url()."/$small_icon";?>" alt="small icon" /></td>
                    </tr>
                </table>
    			<div class="submit"><input type="submit" name="info_update" value="<?php _e('Select Icons','category_icons');?> ยป" /></div>
            </form>
    		</div>
    		<?php
    	break;
    	default:
    	?>
    	<div class="wrap">
            <form id="posts-filter" action="" method="get" name="caticons-form2">
            <?php wp_nonce_field('caticons-nonce'); ?>
                <input type="hidden" name="ig_module" value="caticons" />
                <input type="hidden" name="page" value="category_icons.php" />
                <input type="hidden" name="action" value="delete" />
                <input type="hidden" name="ig_tab" value="icons" />
    
    		<div class="tablenav">
    			<div class="alignleft">
    				<input type="submit" value="<?php _e('Delete icons and priority','category_icons'); ?>" name="deleteit" class="button-secondary delete" />
    			</div>
    			<br class="clear" />
    		</div>
    		<br class="clear" />
    		<table class="widefat" id="caticons_table">
    			<thead>
    			<tr>
       				<th scope="col" id="cb" class="check-column"><input type="checkbox" /></th>
    				<th scope="col"><?php _e('ID','category_icons') ?></th>
                    <th scope="col" ><?php _e('Name','category_icons') ?></th>
                    <th scope="col" style="text-align:center"><?php _e('Description','category_icons') ?></th>
                    <th scope="col" class="num" style="text-align:center"><?php _e('Posts','category_icons') ?></th>
                    <th scope="col" style="text-align:center"><?php _e('Priority','category_icons') ?></th>
    				<th scope="col" style="text-align:center"><?php _e('Icon','category_icons') ?></th>
    				<th scope="col" style="text-align:center"><?php _e('Small Icon','category_icons') ?></th>
    			</tr>
    			</thead>
    			<tbody id="the-list" class="list:cat">
    		<?php
    		bm_caticons_rows();
    		?>
    			</tbody>
    		</table>
    		</form>
            <div class="tablenav">
            <br class="clear" />
            </div>
            <br class="clear" />
            </div>
    	<?php
    	}// end switch
    }

    and install aswell:

    /**
     * Install the plugin
     * @author Ivan Georgiev
     */
    function ig_caticons_install() {
    	global $wpdb, $table_prefix;
    	$wpdb->query($wpdb->prepare( "CREATE TABLE IF NOT EXISTS <code>$wpdb->ig_caticons</code> (<code>cat_id</code> INT NOT NULL ,<code>priority</code> INT NOT NULL ,<code>icon</code> TEXT NOT NULL ,<code>small_icon</code> TEXT NOT NULL , PRIMARY KEY ( <code>cat_id</code> ))", $table ) ) ;
    	add_option('igcaticons_path', '');
    	add_option('igcaticons_url', '');
    	add_option('igcaticons_filetypes', 'jpg gif jpeg png');
    	add_option('igcaticons_max_icons','3');
    	add_option('igcaticons_before_name','true');
    	add_option('igcaticons_fit_width','-1');
    	add_option('igcaticons_fit_height','-1');
    	add_option('igcaticons_use_small','true');
    	add_option('igcaticons_templatecode_patch','0');
    	add_option('igcaticons_templatecode_sidebar','1');
    	add_option('igcaticons_rssfeeds','1');
    	add_option('igcaticons_useseo_plugin', '0');
    	add_option('igcaticons_max_width','-1');
    	add_option('igcaticons_max_height','-1');
    	add_option('igcaticons_iconcatpage','0');
    }

    I hope this helps ..

    Thanks, tadesse, for these updates. However, they’ve had zero effect on the error message I’m receiving, it’s still there, unfortunately.

    Hello,
    id did run the script with debug enabled and improved some php notices
    On our server I get no error messages anymore.
    find the full code of the modified category_icons.php here:
    http://pastebin.com/GSSjg3kE
    It is old code by the way.

    > “hey’ve had zero effect on the error message I’m receiving”

    What exactly do you mean?

    “What exactly do you mean?”

    I mean if I take the original code from the original author and replace it with your code, I still get the same error message, as if I hadn’t changed anything.

    Thank you tadesse! This cleared up the error for me. Where on Earth is the developer in all this?

    Well,
    glad I could be of some help (after some time ๐Ÿ™‚

    Pasting the whole code from the pastebin now also worked for me, finally! many thanks tadesse!!

    Hi tadesse. any chance you can put the complete code back up, seems pastebin has emptied itself.

    Hello,
    yes, ok : http://pastebin.com/XevRdaZg
    I hope it helps …

    Great! works perfectly. Thanks

    Hi Tadesse! Thank you so much for your help on this. Worked like a charm. Is this plugin supported by the developer any longer? Such a great and functional plugin I hope it is.

    Thanks again!

    Yes, thank you so much Tadesse! But I still get an error, maybe you can help me?

    Warning: Missing argument 2 for wpdb::prepare(), called in /public_html/wp-content/plugins/category-icons/category_icons.php on line 919 and defined in /public_html/wp-includes/wp-db.php on line 992

    I’ve copy+pasted your exact lines.

    I still get a notice with the file at pastebin.com/XevRdaZg:

    Notice: wpdb::prepare was called incorrectly. The query argument of wpdb::prepare() must have a placeholder. Please see Debugging in WordPress for more information. (This message was added in version 3.9.) in …/wp-includes/functions.php on line 3245

    Which is solved by changing category_icons.php:1047 to

    $wpdb->query(“CREATE TABLE IF NOT EXISTS $wpdb->ig_caticons(cat_id INT NOT NULL ,priority INT NOT NULL ,icon TEXT NOT NULL ,small_icon TEXT NOT NULL , PRIMARY KEY ( cat_id ))”);

    Note: there’s backquotes/backticks (stripped out by wordpress.org) around all literals = $wpdb->ig_caticons, cat_id, priority, icon, small_icon, and cat_id (again)

    However I still have a recurrent SQL error which I’m unable to locate/fix:

    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 ”cms_ig_caticons” at line 1]
    select count(*) from ‘cms_ig_caticons’
    0

    (I’m guessing that 0 is the culprit.)

Viewing 15 replies - 16 through 30 (of 31 total)
  • The topic ‘Missing Argument 2 for wpdb::prepare’ is closed to new replies.