I have two pages (index.php) and (report.php). The index.php has a modal that takes the data entered by the user (start date and end date). Through this information imputed, is directed to the report.php. The problem that the variables are not being fed into the report.php, generating the error below:
Invalid argument supplied for foreach()
If I access the report.php and put a fixed value in $ sql, the report is generated without problems, but if it depends on the values imputed by the user, the report is generated in white.
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();