Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.
Moderator: General Moderators
offsite
Forum Newbie
Posts: 8 Joined: Tue Jun 25, 2002 12:10 pm
Location: Colchester, CT
Post
by offsite » Sat Jul 06, 2002 12:01 pm
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";
?>
martin
Forum Commoner
Posts: 33 Joined: Fri Jun 28, 2002 12:59 pm
Location: Cambridgeshire
Post
by martin » Sat Jul 06, 2002 1:07 pm
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 » Sat Jul 06, 2002 1:14 pm
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
Post
by offsite » Sat Jul 06, 2002 1:27 pm
You guy's are the best. Changed according to DSM and it worked fine.
Thanks again.
mikeq
Forum Regular
Posts: 512 Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland
Post
by mikeq » Mon Jul 08, 2002 4:40 am
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.