0

I wanna list all the rows from a specific mysql table in another table . But i get this error. I search all google for a something but i can't find nothing . Please help me !

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in 

C:\xampp\htdocs\toate.php on line 38
There are currently rows in the table

Warning: mysql_fetch_row() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\toate.php on line 42

This is my php code :

$user = "boss";
$pass = "123";
$db = "test";
$link =  mysql_connect("localhost", $user, $pass );

if ( ! $link ){
    die( "Couldn't connect to MySQL" );
}

mysql_select_db( $db, $link ) or die ( "Couldn't open $db: ".mysql_error() );
$result = mysql_query( "SELECT * FROM Employee" );

$num_rows = mysql_num_rows( $result );
print "There are currently $num_rows rows in the table<P>";
print "<table border=1>\n";

while ( $a_row = mysql_fetch_row( $result ) ){
    print "<tr>\n";
    foreach ( $a_row as $field )
        print "\t<td>$field</td>\n";
    print "</tr>\n";
}

print "</table>\n";
mysql_close( $link );
Radu Ionuţ
  • 41
  • 1
  • 2
  • 7
  • Is `mysql_query( "SELECT * FROM Employee" );` executing correctly? – Jaydee Nov 10 '14 at 13:30
  • try to put `var_dump($result);` before `$num_rows = mysql_num_rows( $result );` – dandice Nov 10 '14 at 13:31
  • Change `mysql_query( "SELECT * FROM Employee" );` into `mysql_query( "SELECT * FROM Employee" ) or die( "Couldn't execute query: ".mysql_error());` to see what is going wrong. Most obvious problem would be that you misspelled the table name. Is it perhaps `Employees` instead of `Employee` ? – nl-x Nov 10 '14 at 13:40
  • Thank you nl-x . It work now ! – Radu Ionuţ Nov 10 '14 at 13:50

1 Answers1

0

Looks like your query is failing due to a permissions error. mysql_query() returns FALSE if that occurs. Take a look at your database permissions for your user. Also, I suggest using mysqli as the mysql extension is deprecated.

Edit: mysql_result also returns false on errors, so make sure you double check your query syntax.

frost287
  • 81
  • 4