Solved

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

930 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

12 Experts available now in Live!

Get 1:1 Help Now