I'm having a problem with a GET search.
I have the following code:
<?php
//envio o charset para evitar problemas com acentos
header("Content-Type: text/html; charset=UTF-8");
include_once ('bd/bd.php');
$cnpj = filter_input(INPUT_GET, 'cnpj');
$sql = "SELECT * FROM 'fornecedores' WHERE 'cnpj' = '{$cnpj}'"; //monto a query
$query = $mysqli->query( $sql ); //executo a query
if( $query->num_rows > 0 ) {//se retornar algum resultado
echo "Este CNPJ já está cadastrado em nosso banco de dados";
} else {
echo "CNPJ OK";
}
?>
But when I search for ex:
www.site.com/busca-fornec.php?cnpj=85.341.207/0001-82
The result should be: "This CNPJ is already registered in our database", but it is appearing "CNPJ OK"
The CNPJ of the example is saved in the database, if I do SQL directly in phpMyAdmin the result is found, showing that the query is ok, but via GET it always appears "CNPJ OK" regardless of the parameter I pass in query.
If I search:
www.site.com/busca-fornec.php?cnpj=123456789
In theory I should say that the CNPJ is already registered, correct? However it appears that the CNPJ is ok