Jump to content

supplied argument not valid


jeff5656

Recommended Posts

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
}
?>

Link to comment
https://forums.phpfreaks.com/topic/211785-supplied-argument-not-valid/
Share on other sites

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.