jeff5656 Posted August 26, 2010 Share Posted August 26, 2010 I'm trying to list all the tables in my database. I got this code pretty much "word" for word from the example at php.net, but I get: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in E:\wamp\www\test\test-in.php on line 67 <?php $db= $_POST['db']; $sql= "SHOW TABLES FROM $db"; $result=mysql_query($sql); while ($tblarray = mysql_fetch_row($result)){ ?><a href="?tablename=<?php echo $tblarray[0];?>"><?php echo $tblarray[0];?></a><?php } ?> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted August 26, 2010 Share Posted August 26, 2010 Since the code you posted does not contain a mysql_fetch_array() statement, it would be a little hard to directly help you. Try again. Once you identify the actual code where the error is occurring, that error normally means that your query failed due to an error and your code has no error checking logic in it to both tell you that the query failed, what the error is, and to prevent the rest of the code from blindly attempting to access data from a failed query. Quote Link to comment Share on other sites More sharing options...
litebearer Posted August 26, 2010 Share Posted August 26, 2010 old man question - where are you connecting to the database? its appears $db is the NAME of the database. Quote Link to comment Share on other sites More sharing options...
jeff5656 Posted August 26, 2010 Author Share Posted August 26, 2010 To litebearer: db is the name of the database that is out into a post variable. I forgot to his the form submit button thus $db was blank so thank you you solved it! As for PFMaBiSmAd's question: not sure what you mean. Also see above, it's just that db was blank. I guess I don't know the difference between mysql_fetch_array and mysql_fetch_row, but the latter worked after I populated the $db variable. I agree that in the future I should throw in the or DIE (mysql_error) statment but since we are talking about 4 lines of code I didn't feel the need. Quote Link to comment 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.