•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,579 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 2,770 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: 19921 | Replies: 7
![]() |
•
•
Join Date: Sep 2004
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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
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
[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
•
•
Join Date: Sep 2004
Posts: 2
Reputation:
Rep Power: 0
Solved Threads: 0
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))
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))
•
•
Join Date: Sep 2004
Posts: 4
Reputation:
Rep Power: 0
Solved Threads: 0
•
•
•
•
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.
•
•
Join Date: Jun 2005
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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
<?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
•
•
Join Date: Jul 2005
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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'];
}
$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'];
}
•
•
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation:
Rep Power: 4
Solved Threads: 4
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.
"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.
•
•
Join Date: Nov 2007
Posts: 1
Reputation:
Rep Power: 0
Solved Threads: 0
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
<?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
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
- Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource (PHP)
Other Threads in the PHP Forum
- Previous Thread: sms with php
- Next Thread: Run PHP script every 10 seconds


Linear Mode