944,192 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 42146
  • PHP RSS
Sep 9th, 2004
0

mysql_fetch_array(): supplied argument is not a valid MySQL

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Silverhawk is offline Offline
4 posts
since Sep 2004
Sep 9th, 2004
0

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

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
TKS
Reputation Points: 108
Solved Threads: 18
Posting Pro in Training
TKS is offline Offline
470 posts
since Jan 2004
Sep 9th, 2004
0

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

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))
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Silverhawk is offline Offline
4 posts
since Sep 2004
Sep 12th, 2004
0

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

Quote 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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vscapes is offline Offline
4 posts
since Sep 2004
Jun 20th, 2005
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
HellFire is offline Offline
1 posts
since Jun 2005
Jul 16th, 2005
0

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

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'];
}
cab
Reputation Points: 10
Solved Threads: 0
Newbie Poster
cab is offline Offline
1 posts
since Jul 2005
Jul 17th, 2005
0

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

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.
Reputation Points: 36
Solved Threads: 6
Posting Whiz
Troy is offline Offline
354 posts
since Jun 2005
Nov 7th, 2007
0

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

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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
clement108 is offline Offline
1 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: sms with php
Next Thread in PHP Forum Timeline: Run PHP script every 10 seconds





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC