i am working on a search bar which searches in a SQLSRV database.I cannnot use the sanitization method for mysql since sqlsrv doesn't have such thing. So, after looking on the internet, i used a few techniques, mostly from w3schools.Now, i don't know if they are old or hackable, or even valid.To submit the form i've used this markup :
enter <form action="<?php echo htmlspecialchars('cautare.php');?>" method="post" id="formular" name="formular">code here
in the hopes that a hacker won't be able to introduce code in the link to execute it. Then, in the php:
$search = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$search = test_input($_POST["search"]);
}
function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
This part is from W3Schools and it seems safe enough, after i've read their explanation a couple times. I've done all this was to protect from a SQL Injection attack since i'm using this code to search the database:
WHERE den_produs LIKE '%{$search}%'
I'd like to know if there is a better way of doing this and what i am doing wrong.
Thanks a lot for your time!