Supplied argument is not a valid MySQL result resource

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
offsite
Forum Newbie
Posts: 8
Joined: Tue Jun 25, 2002 12:10 pm
Location: Colchester, CT

Supplied argument is not a valid MySQL result resource

Post by offsite »

Hi Folks,

I am getting the abve error with this script.
Any Suggestions Why?
$db = mysql_connect($DBhost, $DBuser, $DBpass) or die("News=Uh Oh, Could not connect");
mysql_select_db("$DBName", $db);

$sql ='SELECT * FROM $table WHERE CompanyCode = "'.$CompanyCode.'"';
$result = mysql_query($sql);

$row = mysql_fetch_array($result); //error points to this line//

$Contact = $row["1"];
$Phone = $row["2"];
$reason = $row["3"];
$version = $row["4"];
$bill = $row["5"];
$comments = $row["6"];

echo 'Company Code ' .$CompanyCode."<br><br>\n";
echo 'Contact: '.$Contact."<br><br>\n";
echo 'Phone Number: '.$Phone."<br>\n";
echo 'Reason for upgrade request: '.$reason."<br>\n";
echo 'Version requested: '.$version."<br>\n";
echo 'Upgrade billable? '.$bill."<br><br>\n";
echo 'Comments: '.$comments."<br>\n";
?>
User avatar
martin
Forum Commoner
Posts: 33
Joined: Fri Jun 28, 2002 12:59 pm
Location: Cambridgeshire

Post by martin »

The error is because mysql is returning no results. Try echoing out your query statement to make sure it contains all the right data.

Code: Select all

$db = mysql_connect($DBhost, $DBuser, $DBpass) or die("News=Uh Oh, Could not connect"); 
mysql_select_db("$DBName", $db); 

$sql ='SELECT * FROM $table WHERE CompanyCode = "'.$CompanyCode.'"'; 
echo $sql;
You could then try running the query directly to mysql to see if it returns rows.
DSM
Forum Contributor
Posts: 101
Joined: Thu May 02, 2002 11:51 am
Location: New Mexico, USA

Post by DSM »

Code: Select all

$sql ='SELECT * FROM $table WHERE CompanyCode = "'.$CompanyCode.'"';
Needs to be

Code: Select all

$sql ="SELECT * FROM $table WHERE CompanyCode = '$CompanyCode'";
offsite
Forum Newbie
Posts: 8
Joined: Tue Jun 25, 2002 12:10 pm
Location: Colchester, CT

returning no results

Post by offsite »

You guy's are the best. Changed according to DSM and it worked fine.

Thanks again.
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

martin wrote:The error is because mysql is returning no results
Not true, it is perfectly valid for a query to return no rows and it will not produce an error.
Post Reply