Solved

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

Posted on 2007-12-05
4
975 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 125 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
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 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…

624 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