im creating a search bar, this bar if we put for example plants, i want to search all the things with the name plants, what is the problem, im working with image and with SQL Statement, and I have a problem.
I have the error Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064
because I put LIKE%
, the operator for search, and I have an error.
The Public function:
public function viewbusq()
{
$busqueda=$_GET["buscar"];
$SQLStatement = $this->DBConexion->prepare("SELECT * FROM productosima LIKE'%$busqueda%'");
$SQLStatement->execute();
while($img = $SQLStatement->fetch(PDO::FETCH_ASSOC))
{
<div class="producto">
<div class="name_producto"><?php print($img['id']); ?></div>
<div class="cajafoto">
<div><img class="img_producto" src="<?php print($img['imagen']); ?>"/></div>
<a href="#"><input type="button" class="btn btn-success" value="See"></a>
</div>
</div>
<?php
}
}
Page that make the search in the DB:
<?php
$busqueda=$_GET["buscar"];
require("BSQparametros.php");
$conexion=mysqli_connect (DB_HOST,DB_USER,DB_PASSWORD,DB_DATABASE);
if(mysqli_connect_errno() ){
exit();
}
mysqli_select_db($conexion,DB_DATABASE) or die ("No results");
mysqli_set_charset($conexion, "utf8");
$consulta="SELECT * FROM productosima WHERE imagen LIKE'%$busqueda%'";
$resultados=mysqli_query($conexion, $consulta);
while($fila=mysqli_fetch_array($resultados, MYSQLI_ASSOC))
{
?>
<?php
include 'MOST.coneccion.php';
if(isset($_POST['save']))
{
$DBImagen->uploadImage($_FILES);
}
$DBImagen->viewbusq();
?>
<?php
}
mysqli_close($conexion);
?>