Rui Paredes Rui Paredes - 1 year ago 58
PHP Question

Search on mysql php

I'm have been working on a website for a class context and I'm doing a search field that goes to mysql database table and return a matched result.

I make this code but its not working and the error is like "Array to string conversion" I have searched for hours and cant find a solution. Here is my code:

if(!empty($_POST) ){

$searchstring['string'] = $_POST['string'];
$productManager = new ProductManagement();

$results = $productManager->searchProduct($searchstring);

if (!$results) {
echo "nothing found";
} else {
while($row = $results->fetch_array(MYSQLI_ASSOC)) {

echo '

<div class="col-sm-4 col-lg-4 col-md-4">
<div class="thumbnail">
<img src="'. $row ['image'] .'" alt="" width="320px" weight="150px">
<div class="caption">
<h4 class="pull-right">€'. $row ['price'] .'</h4>
<h4><a href="#">'. $row ['name'] .'</a>
<p><strong>Size:</strong> '. $row ['size'] .'</p>
<p class="pull-right"><a class="btn btn-info" href="view.php?id='. $row ['id_shirt'] .'" role="button">Ver</a></p>




public function searchProduct($searchstring)
$results = $this->_database->performQuery("SELECT * FROM `shirts` WHERE name LIKE '%".$searchstring."%'");


I hope you can help me thanks!

Answer Source

Simply use this:

$searchstring = $_POST['string'];

insted of this:

$searchstring['string'] = $_POST['string'];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download