1
I have two pages (index.php) and (report.php). index.php has a modal that takes the data entered by the user (start date and end date). Through this imputed information, it is directed to the report.php. The problem that variables are not being fed into the.php report, generating the error below:
Invalid argument supplied for foreach()
If I access the.php report and put a fixed value in $sql, the report is generated without problems, however if it depends on the values imputed by the user, the report is generated blank.
relatorio.php
<?php
#include("conexao.php");
include("mpdf.php");
$grupo = selectAllPessoa();
$datainicio = $_POST['starts_at'];
$datafim = $_POST['ends_at'];
function abrirBanco(){
$conexao = new mysqli("localhost", "xxx", "xxxx", "xxx");
return $conexao;
}
function selectAllPessoa(){
$banco = abrirBanco();
$sql = ("select * FROM xxxx WHERE resolution BETWEEN ('$datainicio') AND ('$datafim')");
$resultado = $banco->query($sql);
$banco->close();
while ($row = mysqli_fetch_array($resultado)) {
$grupo[] = $row;
}
return $grupo;
}
$mpdf = new mPDF();
$mpdf->SetDisplayMode("fullpage");
$mpdf->WriteHTML("<h1>Relatorio - Denuncia</h1><hr/>");
$html = "<table>
<thead>
<tr>
<th>Nickname</th>
<th>Sala</th>
<th>Data </th>
</tr>
</thead>
<tbody>";
foreach ($grupo as $pessoa) {
$html = $html ." <tr>
<td>{$pessoa["nickname"]}</td>
<td>{$pessoa["sala"]}</td>
<td>{$pessoa["resolution"]}</td>
</tr>";
}
$html = $html ." </tbody>
</table>";
$mpdf->WriteHTML($html);
$mpdf->Output();
exit();
It includes the suggested line and the error no longer occurs, but the report still remains blank. The form is sending in the right format 0000-00-00.I believe it is not receiving the post values.
– user54154
That’s right, I inserted the variables $datainicio = $_POST['starts_at']; $datafim = $_POST['ends_at']; within the function selectAllPessoa () and solved. Thank you for your attention.
– user54154