0

Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

I have this mysql query--

$mycms_query="SELECT * FROM `admin` WHERE `login`=`admin`";
$mycms_row=mysql_query($mycms_query);
echo mysql_error();
while($mycms_show=mysql_fetch_array($mycms_row)){
echo $mycms_show[passwd];
}

But when I run it it shows me this--

Unknown column 'admin' in 'where clause'

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\mycms_res\scripts\php\mycms_functions.php on line 38

Community
  • 1
  • 1
Jack Billy
  • 7,021
  • 6
  • 26
  • 38

2 Answers2

3
$mycms_query="SELECT * FROM `admin` WHERE `login`='admin'";

When you use quotes like `, MySQL thinks you want a column.

So, generally speaking, you can do:

SELECT * FROM `admin` WHERE `login`='admin';
SELECT * FROM `admin` WHERE `login`="admin";

but when you do:

SELECT * FROM `admin` WHERE `login`=`admin`

you want MySQL to compare two columns in where condition -> login and admin (which you obviously don't have).

Additionally, bear in mind that when using PostgreSQL, you cannot use " operator, as it will have the same meaning as ` in MySQL.

mailo
  • 2,571
  • 21
  • 19
0

You must use this

$mycms_query="SELECT * FROM `admin` WHERE `login`= 'admin'";

` is used to represent column name.

Gaurav
  • 27,714
  • 8
  • 48
  • 78