When entering a value in the input text, I should check the database to see if it exists. If so, should I redirect to formDetails.php. If not, I should redirect to formRegister.php.
I've been working on this for a few hours and can not find a solution. HTML and Javascript are found in the same file.
<!--FILTRO FLUTUANTE -->
<div id="mws-themer">
<div id="mws-themer-hide"></div>
<div id="mws-themer-content">
<div class="mws-themer-section">
<form action="" name="myForm" id="myForm" style="padding: 0; margin: 0;" method="POST">
<input type="text" name="edtMFIR" id="edtMFIR" value="" class="mws-textinput error">
</form>
</div>
<div class="mws-themer-separator"></div>
<div class="mws-themer-section">
<button type="button" onclick="submit()" class="mws-button red small" id="mws-themer-sendfilterPCD">Filtrar</button>
</div>
</div>
</div>
<script>
function submit() {
var fornDetails = "fornDetails.php";
var fornRegister = "fornRegister.php";
var result = "<?php paginaDestino($_POST["edtMFIR"]); ?>";
alert(result);
if (result) {
myForm.action = fornRegister;
} else {
myForm.action = fornDetails;
}
myForm.submit();
}
</script>
Function where I check in the bank:
function paginaDestino($edtMFIR){
$conexao = new bancodedados();
if(!empty($edtMFIR)){
$conexao->setSQL("SELECT * FROM tab_aro_pcd_riscos WHERE aro_riscos_mfir=".$edtMFIR." LIMIT 1");
$res_a = $conexao->Consultar();
$RES_MFIR = mysql_fetch_array($res_a);
if(empty($RES_MFIR)){
return false;
}else{
return true;
}
}
}
Can anyone help me?