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
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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.