Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html lang="pt-br">
- <head>
- <meta charset="utf-8">
- <title>Agenda</title>
- </head>
- <body>
- <h2>Pesquisa de Contatos</h2>
- <form method="post" action="pesquisa.php">
- <label>Nome parcial:</label>
- <input type="text" name="nome" />
- <button type="submit">Pesquisar</button>
- </form>
- <h2>Listagem de Contatos</h2>
- <?php
- $nome = '';
- if (isset($_POST['nome'])){
- $nome = $_POST['nome'];
- }
- /* Conectando com o banco de dados para listar registros */
- $datasource = 'mysql:host=localhost;dbname=agenda';
- $user = 'root';
- $pass = 'vertrigo';
- $db = new PDO($datasource, $user, $pass);
- $query = "SELECT * FROM contato WHERE nome LIKE '%$nome%'";
- $stm = $db -> prepare($query);
- if ($stm -> execute()) {
- print "<table border>
- <tr>
- <th>Nome</th>
- <th>Email</th>
- <th>Telefone</th>
- <th>Ações</th>
- </tr>";
- while ($row = $stm -> fetch()) {
- $id = $row['contatoid'];
- $nome = $row['nome'];
- $email = $row['email'];
- $telefone = $row['telefone'];
- print "<tr>
- <td>$nome</td>
- <td>$email</td>
- <td>$telefone</td>
- <td>
- <a href='delete.php?id=$id'>Delete</a> |
- <a href='edita.php?id=$id'>Edita</a>
- </td>
- </tr>";
- }
- print "</table>";
- } else {
- print '<p>Erro ao listar!</p>';
- }
- ?>
- <a href='index.php'>Voltar</a>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement