My search didn't work

Question

My search won't work and I don't know why. I would like to search for clients or tickets in my database. When I click on search while the SEARCH field ( input) is empty I get all clients BUT when I type some thing into the field I get nothing. Here is the code :

<table class="table table-bordered" id="datatable">
            <thead>
            <tr>
                <th width="6%">name</th>
                <th width="6%">prenom</th>
                <th width="12%">adresse</th>
                <th width="3%">codepost</th>
                <th width="6%">ville</th>
                <th width="5%">telephone</th>
                <th width="8%">email</th>
                <th width="6%">type</th>
                <th width="5%">Action</th>
            </tr>
            </thead>
            <tbody>
            <?php
            require 'database.php';

           $db = Database::connect();

            $statement = $db->query("SELECT * FROM clients WHERE 'prenom' LIKE '%" . $_POST['prenom'] . "%' ORDER BY client_id DESC" );

          while($item = $statement->fetch())
            {
                echo '<tr>';
                // echo '<td>'. $item['id'] . '</td>';
                echo  '<td>'. $item['name'] . '</td>';
                echo  '<td>'. $item['prenom'] . '</td>';
                echo  '<td>'. $item['adress'] . '</td>';
                echo  '<td>'. $item['codepost'] . '</td>';
                echo  '<td>'. $item['ville'] . '</td>';
                echo  '<td>'. $item['telephone'] . '</td>';
                echo  '<td>'. $item['email'] . '</td>';
                echo  '<td>'. $item['type'] . '</td>';
                echo '<td width=150>';
                echo '<a class="btn btn-default "  href="view.php?id='.$item['client_id'].'"><span class="glyphicon glyphicon-eye-open"></span></a>';
                echo ' ';
                echo '<a class="btn btn-primary" href="update.php?id='.$item['client_id'].'"><span class="glyphicon glyphicon-pencil"></span></a>';
                echo ' ';
                echo '<a class="btn btn-danger" href="deleteclient.php?id='.$item['client_id'].'"><span class="glyphicon glyphicon-remove"></span> </a>';
                echo '</td>';
                echo '</tr>';
            }
            Database::disconnect();
            ?>
            </tbody>
        </table>

Show source
| pdo   | php   | search   2016-12-20 17:12 1 Answers

Answers ( 1 )

  1. 2016-12-21 13:12

    i finaly did it .. thanks to who helped me (
    Sam Onela ) here is the code if some one need ``it := ` name prenom adresse codepost ville telephone email type Action prepare(" SELECT * FROM clients WHERE name LIKE ? "); $req->execute(array('%' .$searchq. '%')) ; $count = $req->rowCount();

                       echo " $count Résulta(s) trouvé pour <strong >$searchq></strong><hr/> " ;
    
                    while($data = $req->fetch()) {
    
                       echo '<tr>';
    
                            echo  '<td>'. $data['name'] . '</td>';
                            echo  '<td>'. $data['prenom'] . '</td>';
                            echo  '<td>'. $data['adress'] . '</td>';
                            echo  '<td>'. $data['codepost'] . '</td>';
                            echo  '<td>'. $data['ville'] . '</td>';
                            echo  '<td>'. $data['telephone'] . '</td>';
                            echo  '<td>'. $data['email'] . '</td>';
                            echo  '<td>'. $data['type'] . '</td>';
                            echo '<td width=150>';
                            echo '<a class="btn btn-default "  href="view.php?id='.$data['client_id'].'"><span class="glyphicon glyphicon-eye-open"></span></a>';
                            echo ' ';
                            echo '<a class="btn btn-primary" href="update.php?id='.$data['client_id'].'"><span class="glyphicon glyphicon-pencil"></span></a>';
                            echo ' ';
                            echo '<a class="btn btn-danger" href="deleteclient.php?id='.$data['client_id'].'"><span class="glyphicon glyphicon-remove"></span> </a>';
                            echo '</td>';
                            echo '</tr>';
    
                                }
    
    
    
                }
    
    
                Database::disconnect();
                ?>
                </tbody>
            </table>`
    
◀ Go back