Reputation: 19
I'm trying to do some verification for my "clients". The client insert his ID and then a window alert pop up saying that he/she is registered (and already paid) or not registered.
But, it returns always the "Inscrição feita e paga!" (Inscription and paid!)
<?php
include("./config.php");
$BI = $_POST['BI'];
$query = mysql_query ("SELECT id_atleta from atleta where num_cidadao = '$BI'");
if ($query)
{
$resultado = mysql_fetch_row($query);
$query2 = "SELECT * FROM inscricao WHERE atleta_id_atleta = '$resultado' AND data_pagamento!= '0000-00-00 00:00:00'";
if ($query2)
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Inscrição feita e paga!')
window.location.href='';
</SCRIPT>");
}
else
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Isncrição a aguardar pagamento!')
window.location.href='';
</SCRIPT>");
}
}
else
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Não existe nenhuma inscrição associada a este BI!')
window.location.href='';
</SCRIPT>");
}
?>
Upvotes: 0
Views: 148
Reputation: 19
Thanks for the help. I know that for security reasons this isn't much help but thanks to your help i managed to correct the code
<?php
include("./config.php");
$BI = $_POST['BI'];
$query = mysql_query ("SELECT id_atleta from atleta where num_cidadao = '$BI'");
if (mysql_num_rows($query))
{
$resultado = mysql_fetch_row($query);
$query2 = mysql_query ("SELECT * FROM inscricao WHERE atleta_id_atleta = '$resultado[0]' AND data_pagamento!= '0000-00-00 00:00:00'");
if (mysql_num_rows($query2))
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Inscrição feita e paga!')
window.location.href='';
</SCRIPT>");
}
else
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Isncrição a aguardar pagamento!')
window.location.href='';
</SCRIPT>");
}
}
else
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Não existe nenhuma inscrição associada a este BI!')
window.location.href='';
</SCRIPT>");
}
?>
Upvotes: 0
Reputation: 507
Try getting the number of rows:
$result = mysql_query($query2, $link);
$num_rows = mysql_num_rows($result);
if ($num_rows === 1) {
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Inscrição feita e paga!')
window.location.href='';
</SCRIPT>");
}
else
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Isncrição a aguardar pagamento!')
window.location.href='';
</SCRIPT>");
}
Upvotes: 0
Reputation: 410
See this code:
$query2 = "SELECT * FROM inscricao WHERE atleta_id_atleta = '$resultado' AND data_pagamento!= '0000-00-00 00:00:00'";
if ($query2)
You're not executing the query, you're simply checking if $query2 (a string) is not false or null. So of course, you're going to always get whatever comes after if($query2)
.
Upvotes: 1