What is the difference....!

Discussion in 'PHP' started by strgraphics, Jun 17, 2010.

  1. #1
    i have prepared simple signup form in that i have used this line to check if the email already there in database or not

    
    if(mysql_query("SELECT email FROM $tbl_name1 WHERE email = '$a'"))
    {
    
    echo "email taken";
    }
    
    PHP:
    -------------------------------
    But not worked..
    -------------------------------
    but it worked if i give..
    -------------------------------
    
    if(mysql_num_rows(mysql_query("SELECT email FROM $tbl_name1 WHERE email = '$a'")))
    {
    echo "email taken";
    }
    
    PHP:

    What is the difference....! why first one is wrong........!
     
    strgraphics, Jun 17, 2010 IP
  2. plog

    plog Peon

    Messages:
    298
    Likes Received:
    11
    Best Answers:
    1
    Trophy Points:
    0
    #2
    Short story: the first one is wrong because you are always passing a valid query string to mysql_query. Even if no results are found its still a valid use of mysql_query.

    Now, when turn around and pass that response from mysql_query to mysql_num_rows you have a different scenario. If results are found, then that is valid data you are passing on to mysql_num_rows, if no results are found then that is invalid data you are passing to mysql_num_rows and it responds as such.
     
    plog, Jun 17, 2010 IP
  3. strgraphics

    strgraphics Active Member

    Messages:
    710
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    53
    #3
    Ohh ya k k nice explanation yar... thanks
     
    strgraphics, Jun 17, 2010 IP