Hi everyone! I'm new to PHP and MySQL Database.
For several days I've been breaking my head with a code and I can not find the error at all. :
I have an index.php page, with a form calling the file "cep.php". In this file, I need the command to read the input sent by the user, and check if the data entered does not exist in the "cep" table, in the "CEP" field.
If the zip exists in bd, it redirects to the page "ok.php" If it does not exist, it redirects to the "bad.php" page.
index.php:
<form method="post" action="cep.php" >
<input type="text" class="form-control form-white" placeholder="Digite seu CEP" name="cepinput" id="cepinput" maxlength="9" OnKeyPress="formatar('#####-###', this)" />
<input type="submit" class="btn btn-submit" value="Verificar Disponibilidade" />
</form>
cep.php:
<?php
require "conexao.php";
// Recuperamos o cep enviado pelo formulário
$cep = $_GET['cepinput'];
// Verificamos no banco de dados o cep equivalente
$resultado = mysql_query("SELECT * FROM cep WHERE CEP=$cep");
// Descobrimos o total de registros encontrados
$num_rows = mysql_num_rows($resultado);
// Se houver o cep informado
if ($num_rows > 0) {
// Exibe a página OK
$url = 'ok.php';
echo'<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
// Se não houver o cep informado
}
else {
$urlerro = 'bad.php';
echo'<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$urlerro.'">';
}
?>
The error happens when I hit the "submit" button. It returns the page "bad.php" even though I insert an existing zip in the DB.
Thanks in advance! ;)