WordPress Resize at Upload Plugin mysql_real_escape_string() Error

Home/WordPress Resize at Upload Plugin mysql_real_escape_string() Error

If like me you use the WordPress plugin Resize at Upload, or Resize at Upload Plus, it’s quite likely that you’ll be getting a mysql error when changing the settings.  Something like:

Resize-at-Upload-Error

Access denied for user ''@'localhost' (using password: NO) in /home/accountname/public_html/wp-content/plugins/resize-at-upload/resize-upload.php on line 63

And seeing as the plugins seem to be abandoned with no updated for many years, you may be mistaken in thinking you’ll need to source an alternative.  Not so.  Fortunately the fix is relatively simple.

From your WordPress Dashboard go to Plugins > Editor and select the Resize and Upload (or Plus) plugin from the top-right dropdown.  Now, in the resize-upload.php file, scroll down and find the section that looks like the code below:

/* the real option page */
function hz_uploadresize_options(){
 if (isset($_POST['hz_options_update'])) {
 $maxwidth = trim(mysql_real_escape_string($_POST['maxwidth']));
 $yesno = $_POST['yesno'];

To fix your problem, you’ll need to replace the line that starts with $maxwidth= to the following:

$maxwidth = trim( esc_sql($_POST['maxwidth']) );

If you’re using the Plus version you will also have a maxheight variable, so you’ll need to apply the same fix as follows:

$maxheight = trim( esc_sql($_POST['maxheight']));

The problem is that the mysql_real_escape_string() command is deprecated and needs an active MySQL connection to work.  Apply those fixes and the plugin will continue to work as intended.

2017-05-19T15:48:04+00:00 June 26th, 2016|PHP Snippets, WordPress Snippets|1 Comment

About the Author:

Warren Chandler is a freelance web programmer and web developer, based in Frinton on Sea, Essex. Warren specialises in web programming, web design, corporate identity, copy writing, SEO, logo and print media for home, work, and mobile platforms.

One Comment

  1. Yafi February 28, 2017 at 5:20 am - Reply

    It was really helpful. Thank you

Leave A Comment