I am making a print report with TCPDF, but I am experiencing some difficulties in redirecting if the code is invalid. see the following code:
if(isset($_GET['CODIGO']) AND $_GET['CODIGO'] != ''){
$html = '';
$item = 1;
$dados = filter_var($_GET['CODIGO'], FILTER_SANITIZE_NUMBER_INT);
$sql = "SELECT * FROM TESTE_TABELA WHERE CODIGO = $dados";
$query = sqlsrv_query($conexion,$sql);
while($row = sqlsrv_fetch_array($query)){
$cod = 0;
$manufacturero = $row['NOME'];
$imagen = $row['IMG'];
if($row['CODIGO']){
$pdf = new TCPDF('P', 'mm', 'A4', true, 'UTF-8', false);
$pdf->SetTitle('Imprimir Imagem'); //Titlo del pdf
$pdf->setPrintHeader(false); //No se imprime cabecera
$pdf->setPrintFooter(false); //No se imprime pie de pagina
$pdf->SetMargins(20, 20, 20, false); //Se define margenes izquierdo, alto, derecho
$pdf->Cell(200, 30, 'Relatório', 1, '', 'center', '', '', '', '');
$pdf->SetAutoPageBreak(true, 20); //Se define un salto de pagina con un limite de pie de pagina
$pdf->addPage();
//$barcode = '';
//$barcode = $pdf->serializeTCPDFtagParameters(array($barcode, 'C128', '', '', 72, 25, 0.5, array('position'=>'S', 'border'=>false, 'padding'=>2, 'fgcolor'=>array(0,0,0), 'bgcolor'=>array(255,255,255), 'text'=>true, 'font'=>'helvetica', 'fontsize'=>7, 'stretchtext'=>6), 'N'));
$html .= '
<h3 style="text-align:center; font-family:helvetica;">Nome: '.$manufacturero.'</h3><br><br>
<img src="images/'.$imagen.'" width="520px"><br>';
$item = $item+1;
$pdf->SetFont('Helvetica', '', 10);
$pdf->writeHTML($html, true, 0, true, 0);
$pdf->lastPage();
$pdf->output('Reporte.pdf', 'I');
}else if(!$row['CODIGO']){
echo "<script>window.location.href='index.php'</script>";
}
}
}else{
echo "<script>window.location.href='index.php'</script>";
}
The first if is working fine, if there is no get, and if the url code equals 0 it redirects. The big problem is when it enters the while, then it enters the if it makes the comparison but in case the code does not exist it does not redirect. Example: I have a report with code 7, if I type in url 6 is a report that does not exist, it should enter the first if but be barred in the second, however it does nothing, does not redirect, the page is blank, someone has any idea what it is? Thanks in advance.