BuckeyeTheDog Posted June 26, 2008 Share Posted June 26, 2008 Hello all. I'm a newbie to php. Just installed XAMPP on a Mac and I'm using "PHP and MySQL for Dummies"- sorry. Everything is installed and running fine, but my I can't get my first exercise in accessing MySQL to work... Here is the warning I'm receiving... Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /Applications/xampp/xamppfiles/htdocs/NoDamnWay.php on line 21 And here is my PHP... (I've called out the offending Line 21 below...) <?php echo "<html> <head><title>Test My SQL- It'll be a miracle if this works </title></head> <body>"; $host="localhost"; $user="root"; $password=""; $cxn = mysqli_connect ($host,$user,$password); $sql= "SHOW STATUS"; $result = mysqli_query($cxn,$sql); if($result == false) { echo "<h4>Error: ".mysqli_error($cxn)."</h4>"; } else { echo "<table border='1'> <tr><th>Variable_name</th> <th>Value</th></tr>"; /*LINE 21*/ for($i = 0; $i < mysql_num_rows($result); $i++) { echo "<tr>"; $row_array = mysqli_fetch_row($result); for($j = 0;$j < mysqli_num_fields($result);$j++) { echo "<td>".$row_array[$j]."</td>\n"; } } echo "</table>"; } ?> </body></html> Thanks for helping a newbie!!! Quote Link to comment https://forums.phpfreaks.com/topic/111957-newbie-help/ Share on other sites More sharing options...
cooldude832 Posted June 26, 2008 Share Posted June 26, 2008 well you must have an error somehwere do u have error reporting on? try a new doc <?php phpinfo(); ?> check what error reporting is set to. The not a resource means that your query is failing or your referring to something that isn't a query resource. Quote Link to comment https://forums.phpfreaks.com/topic/111957-newbie-help/#findComment-574623 Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 put ...or die(mysql_error()); after all your mysqli_xxx statements example: $cxn = mysqli_connect ($host,$user,$password) or die(mysql_error()); that should give you some useful information Quote Link to comment https://forums.phpfreaks.com/topic/111957-newbie-help/#findComment-574628 Share on other sites More sharing options...
cooldude832 Posted June 26, 2008 Share Posted June 26, 2008 they have a valid alternative error reporting method there... Quote Link to comment https://forums.phpfreaks.com/topic/111957-newbie-help/#findComment-574630 Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 umm, even if error reporting is on, you won't get mysql_error messages, because it's not an actual error. It just returns false on fail. and anyways, he did post an error msg in the OP so he's got it on on some level. Quote Link to comment https://forums.phpfreaks.com/topic/111957-newbie-help/#findComment-574632 Share on other sites More sharing options...
cooldude832 Posted June 26, 2008 Share Posted June 26, 2008 http://us.php.net/manual/en/function.mysql-query.php It returns FALSE on fail which in their if(FALSE) they report the mysql_error() a valid way of reporting error be it long and not necessary it is valid. Quote Link to comment https://forums.phpfreaks.com/topic/111957-newbie-help/#findComment-574633 Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 oh haha i get it the script does it i guess i should have actually paid more attention my bad. Quote Link to comment https://forums.phpfreaks.com/topic/111957-newbie-help/#findComment-574637 Share on other sites More sharing options...
cooldude832 Posted June 26, 2008 Share Posted June 26, 2008 oh haha i get it the script does it i guess i should have actually paid more attention my bad. Anytime I can call out an admin/mod's mistake I'm happy Quote Link to comment https://forums.phpfreaks.com/topic/111957-newbie-help/#findComment-574638 Share on other sites More sharing options...
BuckeyeTheDog Posted June 26, 2008 Author Share Posted June 26, 2008 Thanks for the help. My wife also pointed out the I was missing the "i" in the "mysqli_num_rows". We fixed that and it is working fine... You guys were great with such quick responses.... Quote Link to comment https://forums.phpfreaks.com/topic/111957-newbie-help/#findComment-574640 Share on other sites More sharing options...
.josh Posted June 26, 2008 Share Posted June 26, 2008 oh haha i get it the script does it i guess i should have actually paid more attention my bad. Anytime I can call out an admin/mod's mistake I'm happy haha hey now admin/mod does not always equal smartest people around... Thanks for the help. My wife also pointed out the I was missing the "i" in the "mysqli_num_rows". We fixed that and it is working fine... You guys were great with such quick responses.... Tell your wife she has a good "i" for detail Quote Link to comment https://forums.phpfreaks.com/topic/111957-newbie-help/#findComment-574644 Share on other sites More sharing options...
cooldude832 Posted June 26, 2008 Share Posted June 26, 2008 just a note the mysqli is a new version of mysql library of functions. A lot of old timers php/mysqlers still use the older mysql library and u might find more support out there. Also I'd throw that book out cause its a piece of crap if its teaching you to program like that. Thirdly what editor do u use to write in? Quote Link to comment https://forums.phpfreaks.com/topic/111957-newbie-help/#findComment-574645 Share on other sites More sharing options...
atl_andy Posted June 26, 2008 Share Posted June 26, 2008 Also I'd throw that book out cause its a piece of crap if its teaching you to program like that. Agreed. Quote Link to comment https://forums.phpfreaks.com/topic/111957-newbie-help/#findComment-574654 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.