Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-17-2006, 07:43 PM   PM User | #1
chornbeck
Regular Coder

 
Join Date: Feb 2006
Posts: 138
Thanks: 11
Thanked 0 Times in 0 Posts
chornbeck is an unknown quantity at this point
Very simple problem with my PHP code (help?)

I keep getting an error message (I guess) that says resource id #3

My echo statement does not output the desired $result

Help?

PHP Code:
<?
  
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;

 } 
?>
chornbeck is offline   Reply With Quote
Old 02-17-2006, 07:52 PM   PM User | #2
Brandoe85
teh Moderatorinator


 
Join Date: Sep 2004
Location: USA
Posts: 2,472
Thanks: 4
Thanked 40 Times in 40 Posts
Brandoe85 will become famous soon enough
What are you expecting it to echo? That is not an error message, you can pass that resource to mysql_fetch_assoc()
And work with your result set.

Good luck;
__________________
-Brando
Why using tables for eating is stupid!
Brandoe85 is offline   Reply With Quote
Old 02-17-2006, 07:53 PM   PM User | #3
Kid Charming
Regular Coder

 
Join Date: Jun 2005
Posts: 804
Thanks: 0
Thanked 0 Times in 0 Posts
Kid Charming is an unknown quantity at this point
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() -- you have to run your $result variable through one of these functions before you can echo anything out of it.
Kid Charming is offline   Reply With Quote
Old 02-17-2006, 08:00 PM   PM User | #4
chornbeck
Regular Coder

 
Join Date: Feb 2006
Posts: 138
Thanks: 11
Thanked 0 Times in 0 Posts
chornbeck is an unknown quantity at this point
Understood, sort of...

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

PHP Code:
<?
  
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"];
  }

 } 
?>
chornbeck is offline   Reply With Quote
Old 02-17-2006, 08:10 PM   PM User | #5
fci
Senior Coder

 
Join Date: Aug 2004
Location: Twin Cities
Posts: 1,345
Thanks: 0
Thanked 0 Times in 0 Posts
fci is an unknown quantity at this point
should be "FirstName, LastName" not "FirstName AND LastName"
fci is offline   Reply With Quote
Old 02-17-2006, 08:14 PM   PM User | #6
chornbeck
Regular Coder

 
Join Date: Feb 2006
Posts: 138
Thanks: 11
Thanked 0 Times in 0 Posts
chornbeck is an unknown quantity at this point
It's always something like that, isn't it.. Thanks for all your help!
chornbeck is offline   Reply With Quote
Old 02-21-2006, 02:48 PM   PM User | #7
degsy
Senior Coder

 
Join Date: Nov 2002
Location: North-East, UK
Posts: 1,265
Thanks: 0
Thanked 0 Times in 0 Posts
degsy is on a distinguished road
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
degsy is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:55 AM.


Advertisement
Log in to turn off these ads.