elias Posted November 27, 2005 Share Posted November 27, 2005 Hi guys 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. Elias Quote Link to comment https://forums.phpfreaks.com/topic/2942-mysql_num_rows-supplied-argument-is-not-valid/ Share on other sites More sharing options...
sqlmc Posted November 27, 2005 Share Posted November 27, 2005 I would try removing the single quotes from the table and attribute names. Also your using a LIKE statement without a wildcard. So try something like this. $result = mysql_query("SELECT * FROM general WHERE header LIKE '%header%' " ); In this example you should get results from your talbe where the attribute header contains a value with the string 'header' within it. Quote Link to comment https://forums.phpfreaks.com/topic/2942-mysql_num_rows-supplied-argument-is-not-valid/#findComment-9893 Share on other sites More sharing options...
ryanlwh Posted November 27, 2005 Share Posted November 27, 2005 just compare the difference between the two queries you've executed: SELECT * FROM general WHERE `header` LIKE 'header' //succeeded in phpMyAdmin SELECT * FROM 'general' WHERE `header` LIKE 'header' //failed in php code as you can see, you've put single quotes around general. Quote Link to comment https://forums.phpfreaks.com/topic/2942-mysql_num_rows-supplied-argument-is-not-valid/#findComment-9903 Share on other sites More sharing options...
elias Posted November 27, 2005 Author Share Posted November 27, 2005 HI guys Thanks for your replies... IT WORKS!!!! ... but not due to quotes... I tried every combination of quotes, sigle, double, normal an funny accent ones... but nothing... For the record and for future reference, the problem was a simple administrative coq-up! In my cPanel administration area, I created the database, then I created the table, then I created the user... and I thought that was it... but later on I realised I had to **Add User to Db**!! This solved the problem and as expected, the result now is: [!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]You are connected to a mySQL database!There are number of rows: 2 I am so pleased I can continue my project. Thanks again for reading and keep up the good work. Elias ... I'll (probably) be back :-) Quote Link to comment https://forums.phpfreaks.com/topic/2942-mysql_num_rows-supplied-argument-is-not-valid/#findComment-9904 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.