Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    138
    Thanks
    11
    Thanked 0 Times in 0 Posts

    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;

     } 
    ?>

  • #2
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    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;

  • #3
    Regular Coder
    Join Date
    Jun 2005
    Posts
    804
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  • #4
    Regular Coder
    Join Date
    Feb 2006
    Posts
    138
    Thanks
    11
    Thanked 0 Times in 0 Posts
    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"];
      }

     } 
    ?>

  • #5
    fci
    fci is offline
    Senior Coder
    Join Date
    Aug 2004
    Location
    Twin Cities
    Posts
    1,345
    Thanks
    0
    Thanked 0 Times in 0 Posts
    should be "FirstName, LastName" not "FirstName AND LastName"

  • #6
    Regular Coder
    Join Date
    Feb 2006
    Posts
    138
    Thanks
    11
    Thanked 0 Times in 0 Posts
    It's always something like that, isn't it.. Thanks for all your help!

  • #7
    Senior Coder
    Join Date
    Nov 2002
    Location
    North-East, UK
    Posts
    1,265
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •