:?: Greetings,
I am brand new to php and mysql so get out the asprin. smile I am making a php file to pull information from dat files to update my database.

When I run http://www.sandpointrealty.com/read2.php I get this error
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/sandpoin/public_html/read2.php on line 187

Line 187 reads $row=mysql_fetch_array($get);

Here are the surrounding lines

//echo "SELECT AgentID FROM Agent WHERE agt_id = '$AgentID' and OfficeID=$OfficeID";
$get = mysql_query("SELECT AgentID FROM Agent WHERE agt_id = '$AgentID' and OfficeID=$OfficeID", $sql);

$strValue = $strValue . $row;
}else if($arrname[$i] == "zoning" && substr(strtolower($dbvalues[$i]), 0, 5) == "resid"){
$strValue = $strValue . "'Residential'";

Can anyone see what my problem is?
Thank you for your time on this, I have been going nuts.

What database are you connecting too and on what host? Do you have that information included in your php file? I.E.

mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("ID: %s Name: %s", $row[0], $row[1]); 

For me, 9 times out of 10 I forget to connect to the database or signify what table I'm fetching from. Perhaps your prob might be the same?


I believe it is connecting to the database. I had lots of errors and got them all corrected except this one. Here is the top of the file. (Note..I took out the userid and password for this post but it is in my file)
Thank you,

$server = "localhost";
$sql = @mysql_connect($server, $userid, $passwd) or die("Couldn't connect!");

$command = "/home/sandpoin/public_html/data/unzip -o /home/sandpoin/public_html/data/idxphotos -d /home/sandpoin/public_html/MLSPhotos";
exec($command, $result);

$fp = fopen("/home/sandpoin/public_html/data/agent.dic", "r");
$intCount = 0;
while (!feof($fp))
$buffer = fgets($fp, 100);
if(substr($buffer, 7, 8) != "")
$arrname[$intCount] = chop(substr($buffer, 7, 8)); //db name
$arrtype[$intCount] = chop(substr($buffer, 3, 1)); //Office or Agent field
//echo "\$arrname[$intCount] = $arrname[$intCount] : \$arrtype[$intCount] = $arrtype[$intCount] <br>";

$fp = fopen("/home/sandpoin/public_html/data/agent.txt", "r");
while (!feof($fp))

:?: Greetings,

$get = mysql_query("SELECT AgentID FROM Agent WHERE agt_id = '$AgentID' and OfficeID=$OfficeID", $sql);


Can anyone see what my problem is?
Thank you for your time on this, I have been going nuts.

I usually find this error is due to some typo in the sql query, in this case $get. Try putting single quotes around the $OfficeID variable like this:


You did so with the previous var but looks like you may have forgot it on the OfficeID var.

Hope this helps.

I get the same error the complete source for my php file is:


$server= ""; /* Address of 1&1 database server */ 
$database= "computer_room";  /* name of database */ 
$table1= "intranet";
$table2= "intranet_subjects";

/* Accessing the server */ 
MYSQL_CONNECT($server) or die ( "<H3>Server unreachable</H3>");
MYSQL_SELECT_DB($database) or die ( "<H3>database not existent</H3>");

$result=mysql_query("SELECT distinct subject, subject_ID FROM $table1, $table2 WHERE $table2.Subject_ID = $table1.sub_FK AND $table2.Del = 0 AND $table1.Del = 0 ORDER BY subject");

while ($row = mysql_fetch_array($result, MYSQL_NUM)) {

echo "<BR>"; 
 echo "<h4>$row[0]</h4>";
 $subjectName = $row[1];

    $result1=MYSQL_QUERY("SELECT URL, Display_Text FROM $table1 WHERE Sub_FK = $subjectName And Del = 0 ");

    while ($row2 = mysql_fetch_array($result1, MYSQL_NUM)) { 

    echo " <li><a href=$row2[0]>$row2[1]</a></li>";

/* Close SQL-connection */ 



i have another copy of it using a different table which works so i don't understand why this doesn't work

I have the same error, and on another very similar page this seems to be working. Can you see the problem?

$link = mysql_connect("localhost", "root", "")
or die("Could not Connect");
mysql_select_db("school") or die("Could not select database");

$result = mysql_query("SELECT prompt FROM prompts WHERE subjectid = '2'
and label = ".$Label." and tasknumber = ".$TaskNumber."");

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


"supplied argument is not a valid MySQL resource" is almost always the result of an invalid SQL statement being passed to the database. When you are using a scripting language to dynamically build a SQL statement, it is VERY easy to introduce problems into your SQL string.

The good news is that this problem is very easy to troubleshoot. Find the line in your code where you execute the SQL statement. (mysql_query() for example). Just above that line add code similar to this:

echo "<hr />".$sql."<hr />";

Replace $sql with your variable name. This will display the SQL statement in the browser. Now examine that SQL statement. Do you see any problems? Yes? Fix them. No? Then Copy & Paste that statement into a Query window in phpMyAdmin or in whatever admin tool you use. Run the statement and see what errors you get. Usually, the database will do a pretty good job of telling you what is wrong with your statement.

Once you discover the problem, modify your PHP (or other script) to remedy the issue.

Cab, one problem I see in your query building line is that you have not enclosed $Label in single quotes. I'm assuming that is a string value and not numeric.

I have the next code in my site:

$s="select * from useri where useri.id=useri.id";

$s=$s." and nume='$nume'";
$s=$s." and prenume='$prenume'";
$s=$s." and mail='$mail'";
$s=$s." and text='$text'";
$q = mysql_query($s);

while ($s = mysql_fetch_array($q))


echo" Hello!";




and I have the same problem:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/labor/public_html/afisare.php on line 46
How can I fix it?

Thank you