problem with validation

This is a discussion on problem with validation within the MySQL Database forums, part of the Database Forums category; Hi everyone, I have a small problem with validation, and cannot seem to find the problem. I have googled for ...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-30-2007
Dave
 
Posts: n/a
Default problem with validation

Hi everyone,

I have a small problem with validation, and cannot seem to find the
problem. I have googled for different ways to do this, but mostly they
all come back with the same code that i am using, yet its not
working!!

this is the code:

$result = mysql_query("SELECT * FROM `code_tbl`
WHERE `code` ='$product' ")
or die(mysql_error());

$description = mysql_fetch_array( $result );
$check = mysql_num_rows( $result );
if($check !=="0" ){
echo "The product is";
echo $description['product_desc'];
exit;
} else {

echo "It does not exist";

}

When i type in a valid code, it comes back with the description
(great), but when i type in one that does not exist, it still comes
back with the first line (The product you have chosen is) with nothing
after it (obviously because it doesnt exist)

Any clues what i have done wrong?

Reply With Quote
  #2 (permalink)  
Old 07-30-2007
Captain Paralytic
 
Posts: n/a
Default Re: problem with validation

On 30 Jul, 11:47, Dave <david.greenh...@praybourne.co.uk> wrote:
> Hi everyone,
>
> I have a small problem with validation, and cannot seem to find the
> problem. I have googled for different ways to do this, but mostly they
> all come back with the same code that i am using, yet its not
> working!!
>
> this is the code:
>
> $result = mysql_query("SELECT * FROM `code_tbl`
> WHERE `code` ='$product' ")
> or die(mysql_error());
>
> $description = mysql_fetch_array( $result );
> $check = mysql_num_rows( $result );
> if($check !=="0" ){
> echo "The product is";
> echo $description['product_desc'];
> exit;
>
> } else {
>
> echo "It does not exist";
>
> }
>
> When i type in a valid code, it comes back with the description
> (great), but when i type in one that does not exist, it still comes
> back with the first line (The product you have chosen is) with nothing
> after it (obviously because it doesnt exist)
>
> Any clues what i have done wrong?


I suspect it is because of:
$check !=="0"

The !== is a strict operator. Its result is only true if both sides
are equal in value and of the same type.

Try

$check !== 0

OR

$check != '0'
(note the use of "" is unnecessary here as you have nothing in the
string to parse)

Reply With Quote
  #3 (permalink)  
Old 07-30-2007
Dave
 
Posts: n/a
Default Re: problem with validation

On 30 Jul, 12:11, Captain Paralytic <paul_laut...@yahoo.com> wrote:
> On 30 Jul, 11:47, Dave <david.greenh...@praybourne.co.uk> wrote:
>
>
>
>
>
> > Hi everyone,

>
> > I have a small problem with validation, and cannot seem to find the
> > problem. I have googled for different ways to do this, but mostly they
> > all come back with the same code that i am using, yet its not
> > working!!

>
> > this is the code:

>
> > $result = mysql_query("SELECT * FROM `code_tbl`
> > WHERE `code` ='$product' ")
> > or die(mysql_error());

>
> > $description = mysql_fetch_array( $result );
> > $check = mysql_num_rows( $result );
> > if($check !=="0" ){
> > echo "The product is";
> > echo $description['product_desc'];
> > exit;

>
> > } else {

>
> > echo "It does not exist";

>
> > }

>
> > When i type in a valid code, it comes back with the description
> > (great), but when i type in one that does not exist, it still comes
> > back with the first line (The product you have chosen is) with nothing
> > after it (obviously because it doesnt exist)

>
> > Any clues what i have done wrong?

>
> I suspect it is because of:
> $check !=="0"
>
> The !== is a strict operator. Its result is only true if both sides
> are equal in value and of the same type.
>
> Try
>
> $check !== 0
>
> OR
>
> $check != '0'
> (note the use of "" is unnecessary here as you have nothing in the
> string to parse)- Hide quoted text -
>
> - Show quoted text -


Cheers for that, the latter one works perfectly.

Dave.

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 06:11 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0