I am absolutely tearing my hair out about this one. I have done checks and double checks but cant fathom it out - I got to the point that I think there is a problem with the PHP installation at my server - but I have come to learn that something very insignificant can make the code falter and the usual response is "blame the tools".
I am creating a new website and have just created a very simple one-liner database.
I just want to access this database, read the row off my one table and come back and report that everything is ok.
The row has 10 entries and through my cPanel phpMyAdmin I can access and perform the query:
SELECT * FROM general WHERE `header` LIKE 'header'
to get a the row details returned to me. (I even tried misstyping "header" to get a "MySQL returned an empty result set"
So, so far so good. I seem to have created the table correctly and a row of data that I can access from the cPanel Admin tool.
The problem starts when I try to access and retrieve data from my website - this is my code:
mysql_connect ("localhost", "user", "*********") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("mydatabase"); print "You are connected to a mySQL database!"; $result = mysql_query("SELECT * FROM 'general' WHERE `header` LIKE 'header'"); $numrows = mysql_num_rows($result); print "There are number of rows: ".$numrows;
The result is very depressing:
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]
You are connected to a mySQL database!
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/mydomain/public_html/indexphp2.php on line 21
There are number of rows:
So as you can see, it keeps on saying that the argument supplied to mysql_num_rows() is not valid...
What am I doing wrong - clearly the fact that it prints the first line, it (seems) to mean that it is connecting to the database, but it cant peform the query...
Could there be a problem with my server, or the database or the table - what do people suggest I try next.
Thanks for yoru time.