User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 403,207 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,707 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 259 | Replies: 2
Reply
Join Date: Apr 2008
Posts: 3
Reputation: Doctoremote is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Doctoremote's Avatar
Doctoremote Doctoremote is offline Offline
Newbie Poster

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

  #1  
Apr 30th, 2008
This maybe an old chessnut to you old sweats but I am a newbie to this.. I getting this error:-
mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\dsg\Mytest.php on line 9
the database is called Camsdb
the table is called DBF
the fields of which there are three
1) refid
2)Datfd
3)Datfd2
the database connects but if fails on line 9

This is the code:

  1. <?php
  2. $con = mysql_connect("192.168.10.6","trevor","trevor");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7. mysql_select_db("Camsdb", $con);
  8. $result = mysql_query("SELECT * FROM DBF");
  9. while($row = mysql_fetch_array($result));
  10. {
  11. echo $row['Datfd'] . " " . $row['Datfd2'];
  12. echo "<br />";
  13. }
  14. mysql_close($con);
  15. ?>


Can someone help me as I am a real nubie to this connection lark

Regards Trevor
Last edited by peter_budo : May 1st, 2008 at 12:19 pm. Reason: Keep It Organized - please use [code] tags
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2006
Location: South Wales
Posts: 159
Reputation: phper is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 11
phper's Avatar
phper phper is offline Offline
Junior Poster

Re: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

  #2  
Apr 30th, 2008
You have closed the while loop.

  1. while($row = mysql_fetch_array($result));

Notice the ; on the end. Remove this and you query should run.

Regards,
Alex.
If you find my post useful please add to my reputation!! Thanks!

ajtrichards web solutions
http://www.ajtrichards.co.uk
Reply With Quote  
Join Date: Apr 2008
Posts: 3
Reputation: Doctoremote is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
Doctoremote's Avatar
Doctoremote Doctoremote is offline Offline
Newbie Poster

Re: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

  #3  
May 1st, 2008
Thanks m8 for that now running sweet :-)
I have found that when ever you get this error it is MYSQL shouting that something is wrong with one of three things
1) The name of your database is wrong
2) The syntax is wrong
3) Variable not set correctly

Thanks for all your help

I have since rewritten the code so that displays properly in a nice box arrangement

  1. <?php
  2. $con = mysql_connect("connection","username","passord");
  3. if (!$con)
  4. {
  5. die('Could not connect: ' . mysql_error());
  6. }
  7. print "Connected to MySQL<br>";
  8.  
  9. mysql_select_db("database name", $con);
  10. $result = mysql_query("SELECT * FROM DSG ORDER BY yourfield");
  11.  
  12. echo "<table border='1'>
  13. <tr>
  14. <th>yourfield</th>
  15. <th>yourfield2</th>
  16. <th>yourfield3</th>
  17. </tr>";while($row = mysql_fetch_array($result))
  18. {
  19. echo "<tr>";
  20. echo "<td>" . $row['yourfield'] . "</td>";
  21. echo "<td>" . $row['yourfield2'] . "</td>";
  22. echo "<td>" . $row['yourfield3'] . "</td>";
  23. echo "</tr>";
  24. }
  25. echo "</table>";
  26.  
  27.  
  28. print "code by doctoremote<br>";
  29.  
  30. mysql_close($con);
  31. ?>
this is free to look at to get going for all those like me who were having problems getting started it save so much time when you do not have to reinvent the wheel.....
Last edited by peter_budo : May 1st, 2008 at 12:19 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:40 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC