-1

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

I'm new to PHP and I'm trying to simply output something from a database.

Here is my code:

<?php
mysql_connect("localhost:3306", "devnullx_user", "thatguy1") or die (mysql_error ());
mysql_select_db("devnullx_mycrosoft") or die(mysql_error());
$strSQL = "SELECT * FROM devnullx_mycrosoft";
$result = mysql_query($strSQL);
while($row = mysql_fetch_array($result)) {
    echo $row['Username'] . "<br />";
}
mysql_close();
?>

And here is the error I am getting: Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/devnullx/public_html/db.php on line 6

I don't really understand PHP the most but I am trying to learn if you help.

thanks.

Roham Rafii
  • 2,793
  • 7
  • 34
  • 44
Adam F
  • 1
  • 2
  • do you have any value in your db? and are you sure that ur database name and your table name is the same? – Furry Oct 12 '12 at 04:10
  • Looks like you are querying the database instead of a table in the database. Verify that first and also implement error handling – janenz00 Oct 12 '12 at 04:13

5 Answers5

2

It means that the query isn't working properly.

mysql_query returns false on error, and a resource otherwise.

You can use mysql_error to find the error message corresponding to the problem.

Good luck!

Fabian Tamp
  • 4,316
  • 2
  • 25
  • 42
2

Replace

$result = mysql_query($strSQL);

to

$result = mysql_query($strSQL) or die(mysql_error());

to find out the error. Meanwhile don't use mysql_* functions , learn mysqli or PDO.

Update:

As you said your table name is mycrosoft So replace

SELECT * FROM devnullx_mycrosoft

to

SELECT * FROM `mycrosoft`
iLaYa ツ
  • 3,887
  • 3
  • 27
  • 45
  • Okay I got that part of it, it says "Table 'devnullx_mycrosoft.devnullx_mycrosoft' doesn't exist" ... Okay I guess I am not putting the info correctly, could you provide the syntax of how to fill my code in? :S – Adam F Oct 12 '12 at 04:26
  • 1
    That means your table name is not there in your `devnullx_mycrosoft` database, check the table name you have provided is correct or not? – iLaYa ツ Oct 12 '12 at 04:30
  • Okay, so I have this, Table 'devnullx_mycrosoft.Username' doesn't exist ... So is the first part the database? or the table? and the second part? thanks again. – Adam F Oct 12 '12 at 04:33
  • what is your `database` name and `table` name exactly? – iLaYa ツ Oct 12 '12 at 04:34
  • Okay the name of my database is devnullx_mycrosoft ... Im 100% Sure of that. The table name however I BELIEVE is just "mycrosoft" , no "" ... thanks. – Adam F Oct 12 '12 at 04:37
  • So your table name is the issue replace `SELECT * FROM devnullx_mycrosoft` to `SELECT * FROM mycrosoft`. Your problem will be solved. – iLaYa ツ Oct 12 '12 at 04:40
  • Okay hehe thanks for that now it works. But I get access denied because of cPanel, but thanks so much for your help. – Adam F Oct 12 '12 at 04:42
0
if(mysql_num_rows($strSQL)>0){
    Your Fetching Code
}
Mohit Bumb
  • 2,397
  • 1
  • 31
  • 51
0
`$strSQL = "SELECT * FROM devnullx_mycrosoft";` 

devnullx_mycrosoft is your database, replace it with the table name. :)

-1

user this

$result = mysql_query($strSQL) or die(mysql_error());

instead of

$result = mysql_query($strSQL);

this will help out you what is the error

Nikhil
  • 16,026
  • 20
  • 63
  • 81
Mohammad Arshi
  • 386
  • 2
  • 9