...

View Full Version : Very simple problem with my PHP code (help?)



chornbeck
02-17-2006, 07:43 PM
I keep getting an error message (I guess) that says resource id #3

My echo statement does not output the desired $result

Help?


<?
if($_POST['submit']){

mysql_connect("*****************"); //Password and login removed for posting

mysql_select_db("orlandoi_referralowners") or die ('I cannot connect to the database because: ' .

mysql_error());


$Referrer=$_POST['ReferralID'];

$result = mysql_query("SELECT FirstName, LastName FROM owner_data WHERE OwnerID = '$Referrer'") or

die(mysql_error());




echo $result;

}
?>

Brandoe85
02-17-2006, 07:52 PM
What are you expecting it to echo? That is not an error message, you can pass that resource to mysql_fetch_assoc() (http://us3.php.net/mysql_fetch_assoc)
And work with your result set.

Good luck;

Kid Charming
02-17-2006, 07:53 PM
mysql_query() doesn't return immediately-echoable data; it returns a resource that contains your data. There are a number of functions to process this resource, such as mysql_fetch_array() (http://us3.php.net/manual/en/function.mysql-fetch-array.php) -- you have to run your $result variable through one of these functions before you can echo anything out of it.

chornbeck
02-17-2006, 08:00 PM
Understood, sort of...

Here's what I changed it to, now I get nothing..


<?
if($_POST['submit']){

mysql_connect("*******************);
mysql_select_db("orlandoi_referralowners") or die ('I cannot connect to the database because: ' .

mysql_error());


$Referrer=$_POST['ReferralID'];

$result = mysql_query("SELECT FirstName AND LastName FROM owner_data WHERE OwnerID = '$Referrer'") or

die(mysql_error());


while ($row = mysql_fetch_assoc($result)) {
echo $row["FirstName"];
echo $row["LastName"];
}

}
?>

fci
02-17-2006, 08:10 PM
should be "FirstName, LastName" not "FirstName AND LastName"

chornbeck
02-17-2006, 08:14 PM
It's always something like that, isn't it.. Thanks for all your help!

degsy
02-21-2006, 02:48 PM
Here is a good tutorial
http://www.zend.com/php/beginners/php101-8.php#Heading5

I prefer the while($row = mysql_fetch_assoc($result)) method



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum