Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2007-12-05
4
Medium Priority
?
987 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
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
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…
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 dynamically set the form action using jQuery.
Suggested Courses

916 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