From dc80894dd9c9f6d2789d2ea2bd0bce01a96c616c Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 16 Feb 2023 14:38:23 -0500 Subject: [PATCH] Added inputSantize function to trim SQL escape and Strip Tags when string enter the database and to tidy up the code --- functions.php | 15 +++++++++++++++ models/contact.php | 13 +++++++------ post.php | 36 ++++++++++++++++++------------------ 3 files changed, 40 insertions(+), 24 deletions(-) diff --git a/functions.php b/functions.php index f48b587c..9c197841 100644 --- a/functions.php +++ b/functions.php @@ -625,3 +625,18 @@ function checkFileUpload($file, $allowed_extensions) return md5(time() . $name) . '.' . $extension; } + +function sanitizeInput($input) { + global $mysqli; + // Remove white space from beginning and end of input + $input = trim($input); + + // Remove HTML and PHP tags + $input = strip_tags($input); + + // Escape special characters + $input = mysqli_real_escape_string($mysqli, $input); + + // Return sanitized input + return $input; +} diff --git a/models/contact.php b/models/contact.php index 1a2af870..d9992c2c 100644 --- a/models/contact.php +++ b/models/contact.php @@ -1,16 +1,17 @@