Numeric value getting through

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Numeric value getting through

Post 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' ;
        
     }
     }
manixrock
Forum Commoner
Posts: 45
Joined: Sun Jul 20, 2008 6:38 pm

Re: Numeric value getting through

Post by manixrock »

however 0 lets it pass
What does 'lets it pass' mean? Does it print 'is valid' or 'not valid'?
Addos
Forum Contributor
Posts: 305
Joined: Mon Jan 17, 2005 4:13 pm

Re: Numeric value getting through

Post by Addos »

It prints it's valid.
Thanks
manixrock
Forum Commoner
Posts: 45
Joined: Sun Jul 20, 2008 6:38 pm

Re: Numeric value getting through

Post 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) {
Post Reply