I try to select a specific data in a database field, in this case I have a field that is called idDepto
and has the values stored 3,4,5,6,7,8
but at the time of executing the query:
$sql = "SELECT Correo, idDepto, Notificacion
FROM notificaciones
WHERE FIND_IN_SET = " . $_POST['id_depto'] . ",idDepto";
At the moment of executing the previous query, no results appear, and well, I decided to use find_in_set because it worked well for me in MySQL, I executed this query in MySQL and it did give me the results.
SELECT `Correo`, `idDepto`, `Notificacion`
FROM `notificaciones`
WHERE FIND_IN_SET(5, idDepto)
Quick solution
Change your query to the following:
According to what you tell us, the
FIND_IN_SET
MySQL function needs to be used()
, leaving it as follows:But in the example that you pose, it is left as follows:
Therefore, it is enough for you to remove the
=
and add the parentheses in the query.Online example!
Note
Which would leave your code as follows:
Although there are better practices , such as prepared queries (prepared statements) , this one that I propose can help you protect a little from what corresponds to SQL Injection or unwanted characters. Since this is responsible for filtering the characters that arrive both by
POST
and byGET
.