Bom dia pessoal, estou trabalhando em um projeto pessoal e pretendo fazer uma página de buscar clientes informando seu nome e CPF por enquanto o código está assim, mas não está funcionando alguém sabe me dizer o por que?
Eis o código abaixo
Código da página / parte do formulário
<form id="demo-form2" data-parsley-validate class="form-horizontal form-label-left" method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">
<div class="form-group">
<label class="control-label col-md-1 col-sm-3 col-xs-12" for="first-name">Nome
</label>
<div class="col-md-6 col-sm-6 col-xs-12">
<input type="text" id="first-name" name="nome" class="form-control col-md-7 col-xs-12">
</div>
</div>
<div class="form-group">
<label class="control-label col-md-1 col-sm-3 col-xs-12" for="last-name">CPF<span class="required">*</span>
</label>
<div class="col-md-3 col-sm-6 col-xs-12">
<input type="text" id="last-name" name="cpf" class="form-control col-md-3 col-xs-12">
</div>
</div>
<div class="ln_solid"></div>
<div class="form-group">
<div class="col-md-6 col-sm-6 col-xs-12 col-md-offset-3">
<a href="index.html"><button class="btn btn-round btn-danger" type="button">Cancelar <span class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span></button></a>
<button class="btn btn-round btn-warning" type="reset">Resetar <span class="glyphicon glyphicon-repeat" aria-hidden="true"></span></button>
<button type="submit" class="btn btn-round btn-primary">Buscar <span class="glyphicon glyphicon-search" aria-hidden="true"></span></button>
</div>
</div>
</form>
Parte de listar os registros
<tbody>
<?php if(isset($_POST['submit'])): ?>
<?php foreach ($cliente->findClientes($nome,$cpf) as $key => $value): ?>
<tr class="even pointer">
<td class=" "><?php echo $value->id; ?></td>
<td class=" "><?php echo $value->nome; ?></td>
<td class=" "><?php echo $value->profissao; ?></td>
<td class="celula"><?php echo $value->endereco; ?></td>
<td class=" "><?php echo $value->numhab; ?></td>
<td class="telefone" style="width: 150px"><?php echo $value->telefone1; ?></td>
<td class="telefone" style="width: 150px"><?php echo $value->telefone2; ?></td>
<td class=" "><?php echo $value->bairro; ?></td>
<td class=" "><?php echo $value->cidade; ?></td>
<td class=" "><?php echo $value->uf; ?></td>
<td class=" "><?php echo $value->cep; ?></td>
<td class="cpf"><?php echo $value->cpf; ?></td>
<td class=" "><?php echo $value->email; ?></td>
<td class=" " style="text-align: center"><?php echo $value->usuario; ?></td>
<td class=" last" style="width: 100px"> <?php echo "<a href='condutores.php?id=" . $value->id . "'>Condutores <span class='glyphicon glyphicon-user' aria-hidden='true'></span></a> "; ?></td>
<td class=" last" style="width: 80px"> <?php echo "<a href='clientes.php?id=" . $value->id . "'>Editar <span class='glyphicon glyphicon-pencil' aria-hidden='true'></span></a> "; ?></td>
<td class=" last" style="width: 80px"> <?php echo "<a class='delete' href='../Controllers/deletarCliente.php?&id=" . $value->id . "' data-confirm-cliente='Deseja excluir este cliente? '>Excluir <span class='glyphicon glyphicon-remove' aria-hidden='true'></span></a> "; ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
<?php foreach ($cliente->findAll() as $key => $value): ?>
<tr class="even pointer">
<td class=" "><?php echo $value->id; ?></td>
<td class=" "><?php echo $value->nome; ?></td>
<td class=" "><?php echo $value->profissao; ?></td>
<td class="celula"><?php echo $value->endereco; ?></td>
<td class=" "><?php echo $value->numhab; ?></td>
<td class="telefone" style="width: 150px"><?php echo $value->telefone1; ?></td>
<td class="telefone" style="width: 150px"><?php echo $value->telefone2; ?></td>
<td class=" "><?php echo $value->bairro; ?></td>
<td class=" "><?php echo $value->cidade; ?></td>
<td class=" "><?php echo $value->uf; ?></td>
<td class=" "><?php echo $value->cep; ?></td>
<td class="cpf"><?php echo $value->cpf; ?></td>
<td class=" "><?php echo $value->email; ?></td>
<td class=" " style="text-align: center"><?php echo $value->usuario; ?></td>
<td class=" last" style="width: 100px"> <?php echo "<a href='condutores.php?id=" . $value->id . "'>Condutores <span class='glyphicon glyphicon-user' aria-hidden='true'></span></a> "; ?></td>
<td class=" last" style="width: 80px"> <?php echo "<a href='clientes.php?acao=editar&id=" . $value->id . "'>Editar <span class='glyphicon glyphicon-pencil' aria-hidden='true'></span></a> "; ?></td>
<td class=" last" style="width: 80px"> <?php echo "<a class='delete' href='../Controllers/deletarCliente.php?&id=" . $value->id . "' data-confirm-cliente='Deseja excluir este cliente? '>Excluir <span class='glyphicon glyphicon-remove' aria-hidden='true'></span></a> "; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
Código da função findClientes
public function findClientes($nome,$cpf){
$conexao = new Conexao();
$sql = "SELECT * FROM $this->table WHERE nome LIKE '%:nome%' AND cpf LIKE '%:cpf%' ";
return $conexao->select($sql, array(":nome" => $nome, ":cpf" => $cpf));
}
Desde já agradeço a ajuda
%
na variável, e não na query:nome LIKE '%:nome%'
ficarianome LIKE :nome
, logo você adiciona o coringa na variável antes de "bindar":$nome = '%'.$nome.'%';