How to build a shortcode which can insert a query string into a DB table

Short codes are for generating HTML for the front end, and no front end functionality should write to the DB because:

  1. With enough traffic it will bring down your site.
  2. If you use caching or CDN for your content it will simply not work at all, if you expect it to work for all page loads.