-2
I created a form with the aim of searching the person’s name and with the start date and end date field, with the intention of taking from the bank the amount of service within a month for this person searched. I was able to assemble to search the total, using SUM in the field, but I can’t find a way to associate the search by date, follow the code I’m trying to assemble:
first file
<form method="POST" action="http://127.0.0.1/AppAtendimentoFisioterapia/php/sistema/relatorio.php">
Fisioterapeuta:<input type="text" name="buscar" size="50"placeholder="Informe o nome do(a) fisioterapeuta"><br><br>
<label for="exampleInputPassword1" class="form-label">Período Inicial</label>
<input name="dtAtendimentoinicial" type="date" class="form-control" placeholder="Date" aria-label="State">
</div>
<div class="col-sm mb-3">
<label for="exampleInputPassword1" class="form-label">Período Final</label>
<input name="dtAtendimentofinal" type="date" class="form-control" placeholder="Date" aria-label="State"><br><br>
<input type="submit" value="Pesquisar">
</form>
2nd file:
<?php
$buscar = $_POST['buscar'];
$dtInicial = date('Y/m/d', strtotime($_POST['dtAtendimentoinicial']));
$dtFinal = date('Y/m/d', strtotime($_POST['dtAtendimentofinal']));
$sql = mysqli_query($conn, "SELECT nmfisioterapeura, SUM(vlreceber), date_format(dtatendimento, '%d/%m/%Y') AS dtatendimento FROM registroatendimento WHERE nmfisioterapeura Like '%'.$buscar.'%' AND BETWEEN '$dtInicial' AND '$dtFinal'");
$row = mysqli_num_rows($sql);
if ($row > 0) {
while ($linha = mysqli_fetch_array($sql)) {
$nomeFisio = $linha['nmfisioterapeura'];
$valorReceber = $linha['SUM(vlreceber)'];
$dtI = $linha['dtatendimento'];
$dtF = $linha['dtatendimento'];
}
}
?>
<tr style="border:1px solid #f2f2f2;">
<td align="center" style="border:1px solid #f2f2f2;"><?php echo $nomeFisio ?></td>
<td align="left" style="border:1px solid #f2f2f2;"><?php echo $valorReceber ?></td>
<td align="center" style="border:1px solid #f2f2f2;"><?php echo $dtInicial ?></td>
<td align="center" style="border:1px solid #f2f2f2;"><?php echo $dtFinal ?></td>
</tr>
I changed, but still error: Fatal error: Uncaught Typeerror: mysqli_num_rows(): Argument #1 ($result) must be of type mysqli_result, bool Given in C: xampp htdocs18 Stack trace: #0 C: xampp htdocs
– Diego
mysqli_query
returnsfalse
in case of failure https://www.php.net/manual/en/mysqli.query.php . I recommend debugging the code, take the value passed in the second parameter of the functionmysqli_query
and run phpMyAdmin to find out where the error is in the query. It could be one of the variables that in the concatenation had no value. I strongly recommend Prepared Statements https://www.php.net/manual/mysqli.quickstart.prepared-statements.php– Olavo Neto