mysql_fetch_array(): supplied argument is not a valid MySQL

Reply

Join Date: Sep 2004
Posts: 4
Reputation: Silverhawk is an unknown quantity at this point 
Solved Threads: 0
Silverhawk Silverhawk is offline Offline
Newbie Poster

mysql_fetch_array(): supplied argument is not a valid MySQL

 
0
  #1
Sep 9th, 2004
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);

$row=mysql_fetch_array($get);
$strValue = $strValue . $row['AgentID'];
}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.
Rain
Reply With Quote Quick reply to this message  
Join Date: Jan 2004
Posts: 468
Reputation: TKS will become famous soon enough TKS will become famous soon enough 
Solved Threads: 18
TKS's Avatar
TKS TKS is offline Offline
Posting Pro in Training

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

 
0
  #2
Sep 9th, 2004
What database are you connecting too and on what host? Do you have that information included in your php file? I.E.

[PHP]
<?php
mysql_connect("localhost", "mysql_user", "mysql_password") or
die("Could not connect: " . mysql_error());
mysql_select_db("mydb");

$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]);
}

mysql_free_result($result);
?> [/PHP]

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?

TKS
My Home Away from Home: Yet Another Linux Blog
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 4
Reputation: Silverhawk is an unknown quantity at this point 
Solved Threads: 0
Silverhawk Silverhawk is offline Offline
Newbie Poster

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

 
0
  #3
Sep 9th, 2004
Greetings,
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,
Rain

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

$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>";
$intCount++;
}
}
fclose($fp);

$fp = fopen("/home/sandpoin/public_html/data/agent.txt", "r");
while (!feof($fp))
Reply With Quote Quick reply to this message  
Join Date: Sep 2004
Posts: 4
Reputation: vscapes is an unknown quantity at this point 
Solved Threads: 0
vscapes vscapes is offline Offline
Newbie Poster

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

 
0
  #4
Sep 12th, 2004
Originally Posted by Silverhawk
[COLOR=RoyalBlue]Greetings,

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

$row=mysql_fetch_array($get);



Can anyone see what my problem is?
Thank you for your time on this, I have been going nuts.
Rain
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:

OfficeID='$OfficeID'

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

Hope this helps.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1
Reputation: HellFire is an unknown quantity at this point 
Solved Threads: 0
HellFire HellFire is offline Offline
Newbie Poster

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

 
0
  #5
Jun 20th, 2005
I get the same error the complete source for my php file is:

<?php

$server= "127.0.0.1"; /* 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 */
MYSQL_CLOSE();

include('url.php3');

?>

i have another copy of it using a different table which works so i don't understand why this doesn't work
Reply With Quote Quick reply to this message  
Join Date: Jul 2005
Posts: 1
Reputation: cab is an unknown quantity at this point 
Solved Threads: 0
cab cab is offline Offline
Newbie Poster

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

 
0
  #6
Jul 16th, 2005
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['prompt'];
}
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 354
Reputation: Troy is an unknown quantity at this point 
Solved Threads: 5
Troy's Avatar
Troy Troy is offline Offline
Posting Whiz

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

 
0
  #7
Jul 17th, 2005
ATTENTION ALL NEWBIES!

"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: [PHP]
echo "<hr />".$sql."<hr />";
exit();
[/PHP] 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.
Troy Wolf is the author of SnippetEdit. "Website editing as easy as it gets." IX Web Hosting
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 1
Reputation: clement108 is an unknown quantity at this point 
Solved Threads: 0
clement108 clement108 is offline Offline
Newbie Poster

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

 
0
  #8
Nov 7th, 2007
I have the next code in my site:


<?php
$i++;
$nume=$rez['nume'];
$prenume=$rez['prenume'];
$mail=$rez['mail'];
$text=$rez['text'];
if(isset($cauta))
{
include('conectare.php');
$s="select * from useri where useri.id=useri.id";

if($nume!='')
$s=$s." and nume='$nume'";
if($prenume!='')
$s=$s." and prenume='$prenume'";
if($mail!='')
$s=$s." and mail='$mail'";
if($text!='')
$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
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC