Page 1 of 1

Numeric value getting through

Posted: Thu Jul 24, 2008 6:12 am
by Addos
Just wondering why when I pass a numeric value of 0 to this query I don’t get any errors when running the code below.

Code: Select all

if (isset($_POST['v_number_1'])){
 ($voucher_1 = $_POST['v_number_1']); 
 
mysql_select_db($database_, $);
$query_GetVouchers1 = "SELECT * FROM vouchers WHERE v_number = '$voucher_1'";
$GetVouchers1 = mysql_query($query_GetVouchers1, $) or die(mysql_error());
$row_GetVouchers1 = mysql_fetch_assoc($GetVouchers1);
$totalRows_GetVouchers1 = mysql_num_rows($GetVouchers1);
}
This returns an not valid message if the number is not in the database and valid if it exists however 0 lets it pass and I guess this is something to do with a true and false value but I’m not really sure.

Code: Select all

if (isset($_POST['v_number_1']) && ($_POST['v_number_1'])=== $row_GetVouchers1['v_number']) {
// if it does exist then point that out
echo  'is  valid ';
    }else
         {
    echo 'not  valid' ;
        
     }
     }

Re: Numeric value getting through

Posted: Thu Jul 24, 2008 7:16 am
by manixrock
however 0 lets it pass
What does 'lets it pass' mean? Does it print 'is valid' or 'not valid'?

Re: Numeric value getting through

Posted: Thu Jul 24, 2008 7:22 am
by Addos
It prints it's valid.
Thanks

Re: Numeric value getting through

Posted: Thu Jul 24, 2008 7:33 am
by manixrock
You've already checked for the v_number in the database, the second check should simply be of the number of rows returned by the statement. Replace this line:

Code: Select all

if (isset($_POST['v_number_1']) && ($_POST['v_number_1'])=== $row_GetVouchers1['v_number']) {
with this

Code: Select all

if (isset($_POST['v_number_1']) && $totalRows_GetVouchers1 > 0) {