Ensured there is a DB link prior to calling mysql_real_escape_string()

Signed-off-by: Jacob Torrey <discipleofranok@gmail.com>