By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,968 Members | 1,684 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,968 IT Pros & Developers. It's quick & easy.

SELECT LIKE returns no result

P: 18
Hi there!

In my script I use the following code:

Expand|Select|Wrap|Line Numbers
  1. $table = "_lisausers"; 
  2. $mypassword; //this is a 'POST' variable
  3. $query =mysql_query("SELECT pwd FROM `$table` WHERE pwd LIKE '$mypassword'" ) or die();
  4. if (mysql_num_rows( $query ) > 0) {
  5.     print "&retour=true";
  6. }
  7. else {
  8.     print "&retour=false";
  9. }
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
Feb 25 '08 #1
Share this Question
Share on Google+
4 Replies


Markus
Expert 5K+
P: 6,050
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.
Feb 25 '08 #2

nomad
Expert 100+
P: 664
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
Feb 25 '08 #3

nomad
Expert 100+
P: 664
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
Feb 25 '08 #4

P: 18
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
Feb 26 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.