Title: Getting errors if &quot;ref&quot; column is NULL
Last modified: August 30, 2016

---

# Getting errors if "ref" column is NULL

 *  Resolved [janus20](https://wordpress.org/support/users/janus20/)
 * (@janus20)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/getting-errors-if-ref-column-is-null/)
 * Since this morning i have got weird erorrs complaining about database insert 
   error when referer is empty like this:
 * Eroare bază de date WordPress Column ‘ref’ cannot be null pentru interogarea 
   INSERT INTO `wp_404_to_301` (`date`, `url`, `ip`, `ref`, `ua`) VALUES (‘2015-
   12-12 18:34:59’, ‘/pagina-de-ajutor/’, ‘78.96.200.252’, NULL, ‘Mozilla/5.0 (Windows
   NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36’)
   efectuată de require(‘wp-blog-header.php’), require_once(‘wp-includes/template-
   loader.php’), do_action(‘template_redirect’), call_user_func_array, _404_To_301_Public-
   >i4t3_redirect_404
 * ==== eng ====
    Database error WordPress Column ‘ref’ cannot be null for query
   INSERT INTO wp_404_to_301`(`date`,`url`,`ip`,`ref`,`ua`) VALUES (‘2015-12-12 
   18:34:59’, ‘/pagina-de-ajutor/’, ‘78.96.200.252’, NULL, ‘Mozilla/5.0 (Windows
   NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36’)
   requested by require(‘wp-blog-header.php’), require_once(‘wp-includes/template-
   loader.php’), do_action(‘template_redirect’), call_user_func_array, _404_To_301_Public-
   >i4t3_redirect_404
 * This is happen if it hits direct a link that does not exist anymore ( via google
   search engine cache or bookmarked old link… etc ).
 * 404-to-301 version si 2.0.9, my php version is 5.4.4-14+deb7u14 and mySql is 
   5.5.38
 * Thank you very much for your time
 * [https://wordpress.org/plugins/404-to-301/](https://wordpress.org/plugins/404-to-301/)

Viewing 11 replies - 1 through 11 (of 11 total)

 *  Plugin Author [Joel James](https://wordpress.org/support/users/joelcj91/)
 * (@joelcj91)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/getting-errors-if-ref-column-is-null/#post-6843646)
 * Hello janus20,
 * Thanks for notifying this. Will fix this soon.
 *  [stefhz](https://wordpress.org/support/users/stefhz/)
 * (@stefhz)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/getting-errors-if-ref-column-is-null/#post-6843880)
 * same here, just fyi.
 *  [gooma2](https://wordpress.org/support/users/gooma2/)
 * (@gooma2)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/getting-errors-if-ref-column-is-null/#post-6843892)
 * We’re getting this issue too. Had our Liquid Web tech people look and it’s an
   issue with the plugin for sure.
 *  Thread Starter [janus20](https://wordpress.org/support/users/janus20/)
 * (@janus20)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/getting-errors-if-ref-column-is-null/#post-6843904)
 * Hi everyone,
 * Until Mr. Joel will fix this here is a _‘patch’_** to it. I am not and do not
   pretend to be a php coder and do not know if it is ok as from a php programmer
   perspective but it works for me just fine.**
 * Here are the steps:
    1. open **wp-content/plugins/404-to-301/public/class-404-
   to-301-public.php** file for editing. Either download file via FTP and edit localy
   with Notepad++ or look for seqvence of code below if you open it with default
   text editor from your ftp program.
 * 2. move to line #143 where is following code
    **$data[‘ref’] = $_SERVER[‘HTTP_REFERER’];**
 * 3. modify/edit line of original code from step 2 with following:
 *     ```
       // $data['ref'] = $_SERVER['HTTP_REFERER'];
       if (!empty($_SERVER['HTTP_REFERER'])) {
       	$data['ref'] = $_SERVER['HTTP_REFERER'];
       } else {
       // if referer value is empty flag it with some custom text in
       // order to avoid db insert errors as 'ref' column is declared
       // as not NULL.
       $data['ref'] = 'N/A - empty referer';
       }
       ```
   
 * *NOte: // means that content of that line will be treat as comment.
 * I hope that helps.
 *  [gooma2](https://wordpress.org/support/users/gooma2/)
 * (@gooma2)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/getting-errors-if-ref-column-is-null/#post-6843905)
 * Wow, thank you so much for taking the time to find a workaround. My errors have
   stopped now, and there doesn’t appear to be any adverse effects:)
 * For anyone not understanding this, just replace that one line of code wiht what
   Janus20 has discovered. That will take care of those pesky server errors until
   the plugin gets updated.
 * Always appreciate people like you!
 *  Plugin Author [Joel James](https://wordpress.org/support/users/joelcj91/)
 * (@joelcj91)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/getting-errors-if-ref-column-is-null/#post-6843906)
 * Hi **janus20**,
 * Thank you for your solution. That should work perfectly! Sorry for being late
   to release a fix. It will be fixed within this weekend along with few other improvements.
 * I appreciate your patience.
 *  [gooma2](https://wordpress.org/support/users/gooma2/)
 * (@gooma2)
 * [10 years, 5 months ago](https://wordpress.org/support/topic/getting-errors-if-ref-column-is-null/#post-6843912)
 * These errors are now getting thrown by the server for this plugin.
 * “WordPress database error Column ‘ua’ cannot be null for query INSERT INTO `wp_404_to_301`(`
   date`, `url`, `ip`, `ref`, `ua`) VALUES (‘2015-12-17 15:02:33’, ‘/?author=1’,‘
   193.201.227.43’, ‘N/A – empty referer’, NULL) made by require(‘wp-blog-header.
   php’), require_once(‘wp-includes/template-loader.php’), do_action(‘template_redirect’),
   call_user_func_array, _404_To_301_Public->i4t3_redirect_404
    [17-Dec-2015 22:
   14:55 UTC] WordPress database error Column ‘ua’ cannot be null for query INSERT
   INTO `wp_404_to_301` (`date`, `url`, `ip`, `ref`, `ua`) VALUES (‘2015-12-17 16:
   14:55’, ‘173.45.72.98’, ‘N/A – empty referer’, NULL) made by require(‘wp-blog-
   header.php’), require_once(‘wp-includes/template-loader.php’), do_action(‘template_redirect’),
   call_user_func_array, _404_To_301_Public->i4t3_redirect_404″
 *  Thread Starter [janus20](https://wordpress.org/support/users/janus20/)
 * (@janus20)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/getting-errors-if-ref-column-is-null/#post-6843918)
 * Hi gooma2,
 * Yeah… i have seen it into my side too. You have to do the same for ‘ua’ column
   as we/you did for ‘ref’ column. Here is the catch:
 * 1. open wp-content/plugins/404-to-301/public/class-404-to-301-public.php file
   for editing. Either download file via FTP and edit localy with Notepad++ or look
   for seqvence of code below if you open it with default text editor from your 
   ftp program.
 * 2. move to line #150 where is following code
    **$data[‘ua’] = $_SERVER[‘HTTP_USER_AGENT’];**
 * 3. modify/edit line of original code from step 2 with following:
 *     ```
       // $data['ua'] = $_SERVER['HTTP_USER_AGENT'];
       if (!empty($_SERVER['HTTP_USER_AGENT'])) {
       	$data['ua'] = $_SERVER['HTTP_USER_AGENT'];
       } else {
       	$data['ua'] = 'N/A - empty user agent! wtf!';
       }
       ```
   
 * kind regards
 *  [gooma2](https://wordpress.org/support/users/gooma2/)
 * (@gooma2)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/getting-errors-if-ref-column-is-null/#post-6843921)
 * Thanks again for this!
 * It’s been enough trying to get AMP’d up for Google News.:)
 *  Plugin Author [Joel James](https://wordpress.org/support/users/joelcj91/)
 * (@joelcj91)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/getting-errors-if-ref-column-is-null/#post-6843924)
 * Hi all,
 * Sorry for the delay. Could you please update to latest version now and check?
   Please let me know the feedback. I have fixed few other issues too.
 *  Thread Starter [janus20](https://wordpress.org/support/users/janus20/)
 * (@janus20)
 * [10 years, 4 months ago](https://wordpress.org/support/topic/getting-errors-if-ref-column-is-null/#post-6843927)
 * Hi,
 * I can confirm that it is working on my side. Thank you very much. ( ua, ref and
   clear logs too )
 * kind regards

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Getting errors if "ref" column is NULL’ is closed to new replies.

 * ![](https://ps.w.org/404-to-301/assets/icon-128x128.png?rev=2251146)
 * [404 to 301 - Redirect, Log and Notify 404 Errors](https://wordpress.org/plugins/404-to-301/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/404-to-301/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/404-to-301/)
 * [Active Topics](https://wordpress.org/support/plugin/404-to-301/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/404-to-301/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/404-to-301/reviews/)

 * 11 replies
 * 4 participants
 * Last reply from: [janus20](https://wordpress.org/support/users/janus20/)
 * Last activity: [10 years, 4 months ago](https://wordpress.org/support/topic/getting-errors-if-ref-column-is-null/#post-6843927)
 * Status: resolved