Page 1 of 1

Supplied argument is not a valid MySQL result resource

Posted: Sat Jul 06, 2002 12:01 pm
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";
?>

Posted: Sat Jul 06, 2002 1:07 pm
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.

Posted: Sat Jul 06, 2002 1:14 pm
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'";

returning no results

Posted: Sat Jul 06, 2002 1:27 pm
by offsite
You guy's are the best. Changed according to DSM and it worked fine.

Thanks again.

Posted: Mon Jul 08, 2002 4:40 am
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.