PHP Search error [closed]

1

I search with existing numMec and it appears to me that it does not exist in the database

<?php
if(isset($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9]#i","",$searchq);
$query = mysql_query("SELECT * FROM bombeiros WHERE numMec = '%$searchq%'") or die("Nao consegue pesquisar");
$count = mysql_num_rows($query);
if($count==0){
    $output='<div class="alert alert-warning alert-dismissable fade-in">
                <a class="close" data-dismiss="alert" aria-label="close">&times;</a>
                <strong>Bombeiro</strong> não existe na base de dados.
            </div>';
}else{
    $nome=$row_bombs['Nome'];
    $num=$row_bombs['numMec'];

    while($row = mysql_fetch_array($query)){
        $output='<div class="col-sm mx-auto" style="padding-top: 20px;">
                    <div class="card" style="width: 300px;">
                        <img class="mx-auto card-img-top" src="img/BVMCN.png" style="width: 50%; padding-top: 10px;"></br>
                        <div class="card-body">
                            <h5 class="card-title"> '.$nome.'</h5>
                            <a href="bombeiro.php?id="'.$num.' class="btn btn-primary col-sm">'.$num.'</a>
                        </div>
                    </div>
                </div>';
    }
}
}
?>
<?php print("$output");?>

and this at the end of the error (Notice: Undefined variable: output)

    
asked by anonymous 20.12.2017 / 13:57

2 answers

0

At the beginning of your code add it like this: $output = '';

The error that had appeared was notifying you that your variable did not exist because it was only set to if(){} so that's why I asked you to write it at the beginning with the empty value or null , now about your search it's very simple your $query is wrong look at the example below.

Current:

$query = mysql_query("SELECT * FROM bombeiros WHERE numMec = '%$searchq%'") or die("Nao consegue pesquisar");

Update for this:

$query = mysql_query("SELECT * FROM bombeiros WHERE numMec = nome da coluna LIKE '%$searchq%'") or die("Nao consegue pesquisar");

Test what will work now.

    
20.12.2017 / 16:20
-2

At the beginning of your code add it like this: $output = '';

    
20.12.2017 / 14:07