Solved

Warning: mysql_fetch_field(): supplied argument is not a valid MySQL result resource

Posted on 2007-12-05
4
956 Views
Last Modified: 2013-12-12
Can anyone see why I'm getting the following PHP error:
Warning: mysql_fetch_field(): supplied argument is not a valid MySQL result resource
The code block is as follows:
$conn = mysql_connect("$myHost","$myUsername","$myPassword");
$sql = "SELECT * FROM users";
$result = mysql_query($sql,$conn);
while ($field = mysql_fetch_field($result))
{
print "$field->name";
}
0
Comment
Question by:xamian
  • 3
4 Comments
 
LVL 21

Expert Comment

by:nizsmo
Comment Utility
try this and see what error you get?

<?php
      $conn = mysql_connect("$myHost","$myUsername","$myPassword") or die(mysql_error());
$sql = "SELECT * FROM users";
$result = mysql_query($sql,$conn) or die(mysql_error());
while ($field = mysql_fetch_field($result))
{
print "$field->name";
}
?>
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 125 total points
Comment Utility
You forgot to select your database, replace the my_database_name with your database name:


<?php
      $conn = mysql_connect("$myHost","$myUsername","$myPassword") or die(mysql_error());
      mysql_select_db("your_database_name");
$sql = "SELECT * FROM users";
$result = mysql_query($sql,$conn) or die(mysql_error());
while ($field = mysql_fetch_field($result))
{
print "$field->name";
}
?>
0
 
LVL 1

Author Closing Comment

by:xamian
Comment Utility
Worked like a charm.  Thank You so much.
0
 
LVL 21

Expert Comment

by:nizsmo
Comment Utility
Glad to help :)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now