0
I have a question. I do not understand why my code is not correct. Please, if you can review it, I would be very happy.
<?php
require_once "db_connect.php";
//conectar banco
$conectar = new PDO("mysql:host=$host;bancodedados=$bancodedados",
$usuario, $senha);
if(isset($_POST['nomeProduto'])){
$nomeProduto = $_POST['nomeProduto'];
$query = $conectar->prepare("SELECT * FROM nilo_db.nilo_tb
WHERE nomeProduto LIKE ?");
$query->execute(array($nomeProduto));
if($query->rowCount() == 0){
while($linha = $query->fetch()){ ?>
<tr class="text-center">
<td><?php echo $linha['nomeProduto']; ?></td>
<td><?php echo $linha['categoriaProduto']; ?></td>
<td><?php echo $linha['codigoProduto']; ?></td>
<td><?php echo $linha['fornecedor']; ?></td>
<td><?php echo $linha['emEstoque']; ?></td>
</tr>
<?php }
}
}
?>
bancodedados=$bancodedados
would not bedbname=algo....
?– rray
So, the connection is working properly, because with Insert is working well. Is that I named the database "bancodedados" same.
– Brian Moreira
If that’s not a problem, then it should be
LIKE
you won’t pass the%
? can put them together in theexecute()
. You could better describe what the problem or symptom of the code is by knocking your eye those were the things I saw 'out of the pattern'.– rray