-4
Where is the error in my code. I do not know why it does not return the search result.
<?php
require_once('db_connect.php');
$conectar = new
PDO("mysql:host=$host;bancodedados=$bancodedados;charset=utf8",
$usuario, $senha);
$nomeProduto = $_POST['nomeProduto'];
$sql = "SELECT * FROM nilo_db.nilo_tb WHERE nomeProduto =
:nomeProduto";
$queryResult = $conectar->prepare($sql);
$queryExec = $queryResult-
>execute(array(":nomeProduto"=>$nomeProduto));
if($queryExec){
if($queryResult->rowCount()>0){
foreach($queryResult as $row){ ?>
<tr>
<td class="col">
<?php echo $row['nomeProduto'] ?>
<?php echo $row['codigoProduto'] ?>
</td>
</tr>
<?php }
}
}
?>
Click [Edit] and put the last lines of the PHP bug log that makes it easy for us to help. There’s a line break in
->
of the execute, but I imagine this was when pasting the code here?– Bacco
Yes, it was when putting the execute here, however, the problem is that it does not return any error.
– Brian Moreira
In the error log always appears (if it is a mistake, it can just happen that your query is not returning anything), so I asked to add.
– Bacco
I have noticed that you have already asked several questions but I also noticed that you have not marked any as accepted. It is good practice to mark an answer as accepted, as in https://i.stack.Imgur.com/evLUR.png and because in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079.
– user60252