I have a field in a MySQL database to which I have previously inserted HTML code; I also have a search engine that, when entering the word, searches for the results. The problem is that the data in HTML I have something like P & public that means Public, and when entering the text in the search engine it does not make me the like
well.
For example, if I write pú, it stops me from doing the search because it can not pass the HTML code to the query and show the results.
My code is:
<?php
$conexion = new mysqli('localhost','','','');
if (mysqli_connect_error()) { echo mysqli_connect_error(); exit; }
$q = "%" . $_POST['q'] . "%";
$consulta= $conexion->prepare("SELECT ar.Titulo_Articulo, ar.Id_Articulo, r.Id_Revista FROM articulos as ar INNER JOIN revista as r on r.Id_Revista = ar.Id_Revista where ar.pdf LIKE ?");
$consulta->bind_param("s", $q);
$consulta->execute();
$res = $consulta->get_result();
if($conexion->affected_rows>0)
{
while($fila=$res->fetch_array())
{
echo '<a href="autenticacion.php?id='.$fila["Id_Revista"].'&articulo='.$fila["Id_Articulo"].'" width="50%" class="sugerencias" onclick="myFunction2('.utf8_encode($fila["Titulo_Articulo"]).')"><br>'.utf8_encode($fila['Titulo_Articulo']).'</a>';
}
}
else
{
echo '<b>No hay sugerencias</b>';
}
$consulta->close();
$conexion->close();
?>
Hi, I update my question, the editor I use is tynimce, I copy and paste the data from a word document and when I insert them in the field, I get html code, what I need is that in the search engine I can perform the like in html, I used htmlentities and $ q="%" does not work. htmlentities ($ _ POST ['q']). "%";
Hello, I think I made a mistake the text is utf-8 not html, I can not put the post variable with html_entities because it is an input, this has to be in the output but what is it? No, I think that if it is in the input, the output has nothing to do since the insertion of data "pú the letter" or "must convert to utf-8 code, I've already used utf-8 decode and encode and nothing
In the end I have solved it, the problem is that tinymce has its documentation and I have put the encoding as raw link after I inserted the variable as htmlentities and I managed to search with htmlentities and at the end I did the search