0
I’m having trouble searching for data by name. Following is the code. From now on, thank you.
<?php include_once 'dbconfig.php'; ?>
<?php include_once 'header3.php'; ?>
<div class="clearfix"></div>
<div class="container" style=" background-color:#69C">
<legend style="color:#FFF" align="center"><h2>Resultado da Busca por Nome</h2></legend>
<form action="" method="get" id='form-contato' class="form-horizontal col-md-10">
<label class="col-md-2 control-label" for="termo" style="color:#FFFFFF">Pesquisar</label>
<div class='col-md-7'>
<input type="text" class="form-control" id="nome" name="nome" placeholder="Infome o Nome">
</div>
<button type="submit" class="btn btn-primary">Pesquisar</button>
<a href='index.php' class="btn btn-primary">Ver Todos</a>
</form>
</div><!--container-->
<div class="clearfix"></div><br />
<div class="container">
<table class='table table-hover table-border table-responsive'>
<tr bgcolor="#99CCFF">
<th>#</th>
<th>Nome</th>
<th>Sobrenome</th>
<th>Email</th>
<th>Telefone</th>
<th colspan="2" align="center">Ação</th>
</tr>
<?php
$nome=(isset($_GET['nome']));
if(!empty($nome))
{
$sql = "SELECT * FROM dbpdo.tbl_usuarios WHERE nome LIKE :nome OR email LIKE :email";
$stm = $DB_con->prepare($sql);
$stm->bindValue(":nome", $nome);
$stm->bindValue(":email", $nome);
$stm->execute();
if($stm->rowCount()>0)
{
while($row=$stm->fetchAll(PDO::FETCH_OBJ))
{
?>
<tr>
<td><?php print($row['id']); ?></td>
<td><?php print($row['nome']); ?></td>
<td><?php print($row['sobrenome']); ?></td>
<td><?php print($row['email']); ?></td>
<td><?php print($row['telefone']); ?></td>
<td align="center">
<a href="edit-data.php?edit_id=<?php print($row['id']); ?>"><i class="glyphicon glyphicon-edit"></i></a>
</td>
<td align="center">
<a href="delete.php?delete_id=<?php print($row['id']); ?>"><i class="glyphicon glyphicon-trash"></i></a>
</td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td>Não existem dados para visualizar!</td>
</tr>
<?php
}
}
?>
</table>
</div><!--container-->
<?php include_once 'footer.php';?>
What’s the problem? Syntax error, returns only a part, returns nothing?
– Jefferson Quesado
Returns nothing.
– Daniel dos Santos
Daniel, take advantage and put in the description of your problem what you told me. What is the value of
$nome
? Print your value on screen– Jefferson Quesado
The value of $name is taken from the $_GET['name method'].
– Daniel dos Santos
Yes, I know. What’s the content? That’s why I asked you to print it on the screen. Maybe like a header
<h1>
to get really big– Jefferson Quesado
OK. The value of $name is 1, whatever name you put in the search.
– Daniel dos Santos
So I guess you don’t have anyone with name 1 or email 1. Emails need @, and name 1 doesn’t make sense.
– Jefferson Quesado
That’s right! And how do I make the value of $name whatever I type in the search?
– Daniel dos Santos
That’s from
form html
that makes a life that I do not move, barely there. Try to access by passing the value in the browser, passing thequery param
in a controlled manner:127.0.0.1/pagina.php?nome=jeff
– Jefferson Quesado
Passing the value in the browser, continues in the same, even because even passing the value in the search, also see the in the browser.
– Daniel dos Santos
I left my reply, the value is one because the isset returned true! he did not assign the value of $_GET['name'] and yes the return of isset($_GET['name']) which is "true or 1" because the value was passed in $_GET...
– Hiago Souza