Database lookup
Posted: Mon Mar 14, 2011 11:24 am
Hi,
I have a database with a couple of tables in it and I am posting data into the filed successfully. After that is done I want to take an entry that a user has posted and compare it to a table called 'codes' of entries (under field 'barcodes') and return the result. (this is for a competition I am running). Here is the second part of my code:
$sel=mysql_query("select * from codes");
while($log=mysql_fetch_array($sel))
{
if($_POST['barcode']==$log['barcode'])
{
echo"CONGRATULATIONS...You have won!";
}
else
{
echo"Sorry, try again";
}
}
This works but filters through all the results in the database and gives me...
CONGRATULATIONS...You have won!Sorry, try againSorry, try again....etc
I only want one result if the person won or not...I cant seem to pinpoint the error...
Please help...thank you
I have a database with a couple of tables in it and I am posting data into the filed successfully. After that is done I want to take an entry that a user has posted and compare it to a table called 'codes' of entries (under field 'barcodes') and return the result. (this is for a competition I am running). Here is the second part of my code:
$sel=mysql_query("select * from codes");
while($log=mysql_fetch_array($sel))
{
if($_POST['barcode']==$log['barcode'])
{
echo"CONGRATULATIONS...You have won!";
}
else
{
echo"Sorry, try again";
}
}
This works but filters through all the results in the database and gives me...
CONGRATULATIONS...You have won!Sorry, try againSorry, try again....etc
I only want one result if the person won or not...I cant seem to pinpoint the error...
Please help...thank you