?
Solved

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

Posted on 2007-12-05
4
Medium Priority
?
980 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 21

Expert Comment

by:nizsmo
ID: 20415219
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 500 total points
ID: 20415227
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
ID: 31412962
Worked like a charm.  Thank You so much.
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20423162
Glad to help :)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

719 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