SELECT LIKE returns no result

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Germaris
    New Member
    • Jan 2008
    • 18

    SELECT LIKE returns no result

    Hi there!

    In my script I use the following code:

    Code:
    $table = "_lisausers"; 
    $mypassword; //this is a 'POST' variable
    $query =mysql_query("SELECT pwd FROM `$table` WHERE pwd LIKE '$mypassword'" ) or die();
    if (mysql_num_rows( $query ) > 0) {
    	print "&retour=true";
    }
    else {
    	print "&retour=false";
    }
    Despite the fact that $mypassword already exists in the $table, this query always gives me a wrong result if I ask an existing or not pwd in this table !!!

    Would you tell me what's wrong in this query and the if/else block?

    Many thanks in advance for your help!

    Regards,
    Gerry
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    I think when you use LIKE you also have to use the % operator.

    [php]
    SELECT * FROM `table` WHERE `column` LIKE '%something%';
    [/php]

    Also, in your: 'or die()' add this: or die(mysql_error ());
    for error checking.

    Comment

    • nomad
      Recognized Expert Contributor
      • Mar 2007
      • 664

      #3
      Originally posted by markusn00b
      I think when you use LIKE you also have to use the % operator.

      [php]
      SELECT * FROM `table` WHERE `column` LIKE '%something%';
      [/php]

      Also, in your: 'or die()' add this: or die(mysql_error ());
      for error checking.
      or you could do this as well
      SELECT * FROM `table` WHERE item_name LIKE 'A%';

      This would find any item that starts with the letter A

      nomad

      Comment

      • nomad
        Recognized Expert Contributor
        • Mar 2007
        • 664

        #4
        Originally posted by markusn00b
        I think when you use LIKE you also have to use the % operator.

        [php]
        SELECT * FROM `table` WHERE `column` LIKE '%something%';
        [/php]

        Also, in your: 'or die()' add this: or die(mysql_error ());
        for error checking.
        sorry I thought the first one did not go thro...

        nomad

        Comment

        • Germaris
          New Member
          • Jan 2008
          • 18

          #5
          Thanks very much to all of you folks for your replies.

          The problem is solved.
          The PHP is okay, it's the way I manipulate the results in my .swf file which was wrong.
          Silly of me !

          Best regards,
          Gerry

          Comment

          Working...