Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

after wordpress update to 3.5+ i get many errors in this plugin. i found that the reason is: http://make.wordpress.org/core/2012/12/12/php-warning-missing-argument-2-for-wpdb-prepare/

I do not understand how to fix it. If anyone can help me with these problems or give me an example of how to fix it.

this is the plugin core file http://pastebin.com/Tk5Gf1HR

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 ‘wp_jsrm_menus’ at line 1 for query SHOW TABLES LIKE wp_jsrm_menus made by activate_plugin, do_action(‘activate_simple-retail-menus/simple-retail-menus.php’), call_user_func_array, jsrm_activate_loop, jsrm_activate
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 ‘wp_jsrm_items’ at line 1 for query SHOW TABLES LIKE wp_jsrm_items made by activate_plugin, do_action(‘activate_simple-retail-menus/simple-retail-menus.php’), call_user_func_array, jsrm_activate_loop, jsrm_activate
PHP Warning: Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 169 and defined in /wp-includes/wp-db.php on line 992
PHP Warning: mysql_fetch_array() expects parameter 1 to be resource, integer given in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 170
PHP Warning: Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 173 and defined in /wp-includes/wp-db.php on line 992
WordPress database error Duplicate column name ‘menuorder’ for query ALTER TABLE wp_jsrm_menus ADD menuorder mediumint(9) NOT NULL made by activate_plugin, do_action(‘activate_simple-retail-menus/simple-retail-menus.php’), call_user_func_array, jsrm_activate_loop, jsrm_activate, jsrm_update_db_tables
PHP Warning: Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 176 and defined in /wp-includes/wp-db.php on line 992
WordPress database error Duplicate column name ‘label’ for query ALTER TABLE wp_jsrm_menus ADD label tinytext NOT NULL made by activate_plugin, do_action(‘activate_simple-retail-menus/simple-retail-menus.php’), call_user_func_array, jsrm_activate_loop, jsrm_activate, jsrm_update_db_tables
PHP Warning: Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 179 and defined in /wp-includes/wp-db.php on line 992
WordPress database error Duplicate column name ‘itemheader’ for query ALTER TABLE wp_jsrm_menus ADD itemheader tinytext NOT NULL made by activate_plugin, do_action(‘activate_simple-retail-menus/simple-retail-menus.php’), call_user_func_array, jsrm_activate_loop, jsrm_activate, jsrm_update_db_tables
PHP Warning: Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 182 and defined in /wp-includes/wp-db.php on line 992
WordPress database error Duplicate column name ‘valueheader’ for query ALTER TABLE wp_jsrm_menus ADD valueheader tinytext NOT NULL made by activate_plugin, do_action(‘activate_simple-retail-menus/simple-retail-menus.php’), call_user_func_array, jsrm_activate_loop, jsrm_activate, jsrm_update_db_tables
PHP Warning: Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 189 and defined in /wp-includes/wp-db.php on line 992
WordPress database error Duplicate column name ‘valueheader2′ for query ALTER TABLE wp_jsrm_menus ADD valueheader2 tinytext NOT NULL made by activate_plugin, do_action(‘activate_simple-retail-menus/simple-retail-menus.php’), call_user_func_array, jsrm_activate_loop, jsrm_activate, jsrm_update_db_tables
PHP Warning: Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 193 and defined in /wp-includes/wp-db.php on line 992
HP Warning: mysql_fetch_array() expects parameter 1 to be resource, integer given in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 194
PHP Warning: Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 197 and defined in /wp-includes/wp-db.php on line 992
WordPress database error Duplicate column name ‘image’ for query ALTER TABLE wp_jsrm_items ADD image tinytext made by activate_plugin, do_action(‘activate_simple-retail-menus/simple-retail-menus.php’), call_user_func_array, jsrm_activate_loop, jsrm_activate, jsrm_update_db_tables
PHP Warning: Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 200 and defined in /wp-includes/wp-db.php on line 992
WordPress database error Duplicate column name ‘linked’ for query ALTER TABLE wp_jsrm_items ADD linked tinyint(1) NOT NULL made by activate_plugin, do_action(‘activate_simple-retail-menus/simple-retail-menus.php’), call_user_func_array, jsrm_activate_loop, jsrm_activate, jsrm_update_db_tables
PHP Warning: Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 203 and defined in /wp-includes/wp-db.php on line 992
WordPress database error Duplicate column name ‘linkurl’ for query ALTER TABLE wp_jsrm_items ADD linkurl tinytext made by activate_plugin, do_action(‘activate_simple-retail-menus/simple-retail-menus.php’), call_user_func_array, jsrm_activate_loop, jsrm_activate, jsrm_update_db_tables
PHP Warning: Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 206 and defined in /wp-includes/wp-db.php on line 992
WordPress database error Duplicate column name ‘itemhidden’ for query ALTER TABLE wp_jsrm_items ADD itemhidden tinyint(1) NOT NULL made by activate_plugin, do_action(‘activate_simple-retail-menus/simple-retail-menus.php’), call_user_func_array, jsrm_activate_loop, jsrm_activate, jsrm_update_db_tables
PHP Notice: Undefined variable: vh in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 212
PHP Warning: Missing argument 2 for wpdb::prepare(), called in /wp-content/plugins/simple-retail-menus/simple-retail-menus.php on line 213 and defined in /wp-includes/wp-db.php on line 992
WordPress database error Duplicate column name ‘value2′ for query ALTER TABLE wp_jsrm_items ADD value2 tinytext NOT NULL made by activate_plugin, do_action(‘activate_simple-retail-menus/simple-retail-menus.php’), call_user_func_array, jsrm_activate_loop, jsrm_activate, jsrm_update_db_tables

the errors comes from this code: i tried to fix as Charles Clarkson suggested but seems not helping.

[11-Oct-2013 05:27:09 UTC] 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 'wp_jsrm_menus' at line 1 for query SHOW TABLES LIKE wp_jsrm_menus made by activate_plugin, do_action('activate_simple-retail-menus/simple-retail-menus.php'), call_user_func_array, jsrm_activate_loop, jsrm_activate
[11-Oct-2013 05:27:09 UTC] 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 'wp_jsrm_items' at line 1 for query SHOW TABLES LIKE wp_jsrm_items made by activate_plugin, do_action('activate_simple-retail-menus/simple-retail-menus.php'), call_user_func_array, jsrm_activate_loop, jsrm_activate
[11-Oct-2013 05:27:11 UTC] 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 'wp_jsrm_menus' at line 1 for query SHOW TABLES LIKE wp_jsrm_menus made by do_action('activate_simple-retail-menus/simple-retail-menus.php'), call_user_func_array, jsrm_activate_loop, jsrm_activate
[11-Oct-2013 05:27:11 UTC] 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 'wp_jsrm_items' at line 1 for query SHOW TABLES LIKE wp_jsrm_items made by do_action('activate_simple-retail-menus/simple-retail-menus.php'), call_user_func_array, jsrm_activate_loop, jsrm_activate
[11-Oct-2013 05:27:11 UTC] 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 'wp_jsrm_menus' at line 1 for query SHOW TABLES LIKE wp_jsrm_menus made by do_action('activate_simple-retail-menus/simple-retail-menus.php'), call_user_func_array, jsrm_activate_loop, jsrm_activate
[11-Oct-2013 05:27:11 UTC] 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 'wp_jsrm_items' at line 1 for query SHOW TABLES LIKE wp_jsrm_items made by do_action('activate_simple-retail-menus/simple-retail-menus.php'), call_user_func_array, jsrm_activate_loop, jsrm_activate
[11-Oct-2013 05:30:45 UTC] 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 'wp_jsrm_menus' at line 1 for query SHOW TABLES LIKE wp_jsrm_menus made by activate_plugin, do_action('activate_simple-retail-menus/simple-retail-menus.php'), call_user_func_array, jsrm_activate_loop, jsrm_activate
[11-Oct-2013 05:30:45 UTC] 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 'wp_jsrm_items' at line 1 for query SHOW TABLES LIKE wp_jsrm_items made by activate_plugin, do_action('activate_simple-retail-menus/simple-retail-menus.php'), call_user_func_array, jsrm_activate_loop, jsrm_activate
share|improve this question
    
From wp-admin disable the plugin "simple-retail-menus". Seems it's the real culprit. Either you have to use another plugin with same features, or you have to fix the plugin with new codes, or you have to develop your own plugin. –  Mayeenul Islam Oct 9 '13 at 6:30
    
Hello @Mayeenul Islam i know i can disable the plugin but i need this plugin for my work. i just need help and direction how to fix this errors. thanks –  need-help Oct 9 '13 at 7:59

1 Answer 1

up vote 3 down vote accepted

prepare() takes at least 2 parameters. Most of your calls to prepare() are not needed.

For example:

$blogids = $wpdb->get_col($wpdb->prepare("SELECT blog_id FROM $wpdb->blogs"));

In this code, if the call to $wpdb->prepare() were valid, it wouldn't do anything. The function doesn't do anything to the first parameter. It manipulates the values in the other parameters passed and then inserts those parameters into the first parameter.

Rewrite it as:

$blogids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );

After all single parameter prepare() calls are removed you should have something like this:

// Update tables with new columns used in this version
$checkmenus = $wpdb->query( $wpdb->prepare( "SELECT * FROM %s LIMIT 1," $jsrm_menu_table ) );
$menucols = mysql_fetch_array($checkmenus);

if ( ! isset( $menucols['menuorder'] ) )
    $wpdb->query( "ALTER TABLE $jsrm_menu_table ADD menuorder mediumint(9) NOT NULL" );

if ( ! isset( $menucols['label'] ) )
    $wpdb->query( "ALTER TABLE $jsrm_menu_table ADD label tinytext NOT NULL" );

if ( ! isset( $menucols['itemheader'] ) )
    $wpdb->query( "ALTER TABLE $jsrm_menu_table ADD itemheader tinytext NOT NULL" );

if ( ! isset($menucols['valueheader'] ) )
    $wpdb->query( "ALTER TABLE $jsrm_menu_table ADD valueheader tinytext NOT NULL" );

// Loop to update the menu table value headers columns according to number of values.
for ( $v = 2; $v <= JSRM_VALUE_COLS; $v++ ) {
    $valh = 'valueheader' . $v;
    if ( ! isset( $menucols[$valh] ) )
        $wpdb->query( "ALTER TABLE $jsrm_menu_table ADD $valh tinytext NOT NULL" );
}

$checkitems = $wpdb->query( "SELECT * FROM $jsrm_item_table LIMIT 1" );
$itemscols = mysql_fetch_array($checkitems);

if ( ! isset( $itemscols['image'] ) )
    $wpdb->query( "ALTER TABLE $jsrm_item_table ADD image tinytext" );

if ( ! isset( $itemscols['linked'] ) )
    $wpdb->query( "ALTER TABLE $jsrm_item_table ADD linked tinyint(1) NOT NULL" );

if ( ! isset( $itemscols['linkurl'] ) )
    $wpdb->query( "ALTER TABLE $jsrm_item_table ADD linkurl tinytext" );

if ( ! isset( $itemscols['itemhidden'] ) )
    $wpdb->query( "ALTER TABLE $jsrm_item_table ADD itemhidden tinyint(1) NOT NULL" );

// Loop to update the menu items value columns according to number of values.
for ( $v = 2; $v <= JSRM_VALUE_COLS; $v++ ) {
    $val = 'value' . $v;
    if ( ! isset($menucols[$vh] ) )
        $wpdb->query( "ALTER TABLE $jsrm_item_table ADD $val tinytext NOT NULL" );
};

update_option( 'jsrm_db_version', JSRM_DB_VERSION );

I also changed the conditionals style and added consistent white space to make the code easier for humans to read.

share|improve this answer
    
Hello @CharlesClarkson, i tried to fix as you suggested but seems not helping. i have updated my question. i write the code that make all this error. can you please take a look on it and tell me how to fix it? thanks. –  need-help Oct 9 '13 at 15:37
    
This is one example of many prepare calls that need to be removed. Did you remove all of them?!? Or just this one? –  Charles Clarkson Oct 10 '13 at 0:52
    
Hello @CharlesClarkson, of course i tried to remove all as you you write. for example: was $wpdb->query( $wpdb->prepare after change $wpdb->query() the same i did with get_col. –  need-help Oct 10 '13 at 4:36
    
What do you mean you tried? You either did it or you didn't. See the edit above. –  Charles Clarkson Oct 10 '13 at 15:35
    
Hi, as i said before, this exactly what i did. but still the same error come :( –  need-help Oct 10 '13 at 19:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.