psyqosis Posted October 15, 2007 Share Posted October 15, 2007 Hi. I think I'm missing something simple... any ideas? I keep getting the error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in... on line 39 Here's the code in question (line 39 is the IF statement) <?php $database= "edited"; $db = mysql_connect(localhost, "edited", "edited"); mysql_select_db("$database", $db); $sql = "SELECT * FROM events;"; $result = mysql_query($sql, $db); if (mysql_num_rows($result) > 0) { while ($myrow = mysql_fetch_array($result) ) { ?> <TR><TD><?php echo $myrow['title']; ?></TD></TR> <TR><TD><?php echo $myrow['date']; ?></TD></TR> <TR><TD><?php echo $myrow['desc']; ?></TD></TR> <?php } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73271-solved-php-newbie-needing-a-little-help/ Share on other sites More sharing options...
teng84 Posted October 15, 2007 Share Posted October 15, 2007 do this $result = mysql_query($sql, $db) or die (mysql_error()); you have invalid query add a mysql_error() to see your error Quote Link to comment https://forums.phpfreaks.com/topic/73271-solved-php-newbie-needing-a-little-help/#findComment-369674 Share on other sites More sharing options...
psyqosis Posted October 15, 2007 Author Share Posted October 15, 2007 Ok, did that and it says "no database selected." I'm confused though... didn't I already do that in the above code? Quote Link to comment https://forums.phpfreaks.com/topic/73271-solved-php-newbie-needing-a-little-help/#findComment-369681 Share on other sites More sharing options...
teng84 Posted October 15, 2007 Share Posted October 15, 2007 LOLOLOLOL do this $db = mysql_connect(localhost, "edited", "edited") or die(mysql_error()); mysql_select_db("$database", $db) or die(mysql_error()); $sql = "SELECT * FROM events;"; $result = mysql_query($sql, $db)or die(mysql_error()); we have to check if you are really connecting Quote Link to comment https://forums.phpfreaks.com/topic/73271-solved-php-newbie-needing-a-little-help/#findComment-369683 Share on other sites More sharing options...
psyqosis Posted October 15, 2007 Author Share Posted October 15, 2007 Ok thanks, now we're getting somewhere! That returns... Access denied for user: 'edit' to database 'edit' However, I'm using the same UN and PW in the mysql_connect function that lets me sign in to my IP control panel and in to MySQL. Quote Link to comment https://forums.phpfreaks.com/topic/73271-solved-php-newbie-needing-a-little-help/#findComment-369690 Share on other sites More sharing options...
teng84 Posted October 15, 2007 Share Posted October 15, 2007 are you sure you have that db name ? Quote Link to comment https://forums.phpfreaks.com/topic/73271-solved-php-newbie-needing-a-little-help/#findComment-369703 Share on other sites More sharing options...
psyqosis Posted October 15, 2007 Author Share Posted October 15, 2007 yes, I've triple-checked the spelling & everything. I can log into my control panel, and click on that DB name and see my tables. This doesn't make any sense to me...! Quote Link to comment https://forums.phpfreaks.com/topic/73271-solved-php-newbie-needing-a-little-help/#findComment-369706 Share on other sites More sharing options...
psyqosis Posted October 15, 2007 Author Share Posted October 15, 2007 Thanks a million for all your help. Apparently I'm dislexic. Quote Link to comment https://forums.phpfreaks.com/topic/73271-solved-php-newbie-needing-a-little-help/#findComment-369708 Share on other sites More sharing options...
teng84 Posted October 15, 2007 Share Posted October 15, 2007 Thanks a million for all your help. Apparently I'm dislexic. ??? ??? ??? Quote Link to comment https://forums.phpfreaks.com/topic/73271-solved-php-newbie-needing-a-little-help/#findComment-369711 Share on other sites More sharing options...
psyqosis Posted October 15, 2007 Author Share Posted October 15, 2007 i had a typo in my DB name. Didn't know about those die statements--they're helpful. thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/73271-solved-php-newbie-needing-a-little-help/#findComment-369718 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.