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
the database connects but if fails on line 9

This is the code:

 $con = mysql_connect("","trevor","trevor");
 if (!$con)
  die('Could not connect: ' . mysql_error());
  mysql_select_db("Camsdb", $con);
  $result = mysql_query("SELECT * FROM DBF");
  while($row = mysql_fetch_array($result));
  echo $row['Datfd'] . " " . $row['Datfd2'];
  echo "<br />";

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

Regards Trevor

Recommended Answers

All 2 Replies

You have closed the while loop.

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

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


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

$con = mysql_connect("connection","username","passord");
if (!$con)
  die('Could not connect: ' . mysql_error());
  print "Connected to MySQL<br>";

mysql_select_db("database name", $con);
  $result = mysql_query("SELECT * FROM DSG ORDER BY yourfield");

 echo "<table border='1'>
</tr>";while($row = mysql_fetch_array($result))
  echo "<tr>";
  echo "<td>" . $row['yourfield'] . "</td>";
  echo "<td>" . $row['yourfield2'] . "</td>";
  echo "<td>" . $row['yourfield3'] . "</td>";
  echo "</tr>";
echo "</table>";

print "code by doctoremote<br>";


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.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.