SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast Davve's Avatar
    Join Date
    Jan 2002
    Location
    Norrkoping, SWEDEN
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Probably something very basic

    But I can't see what!
    PHP Code:
    <?php
    $sql 
    "SELECT epost FROM user2 WHERE userid = '$uid'";
    $email mysql_query($sql);
    echo 
    $email;
    ?>
    I have connected to my database earlier in the code. And I can access records from other fields.
    David Andersson Davve
    -MSc in Media Technology and Engineering:
    Working at AdLibris

  2. #2
    morphine for a wooden leg randem's Avatar
    Join Date
    Jun 2002
    Location
    .chicago.il.us
    Posts
    957
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $sql 
    "SELECT epost FROM user2 WHERE userid = '$uid'";
    if(
    $rs=mysql_query($sql) && $row=mysql_fetch_array($rs)){
       
    $email $row['epost'];
       
    mysql_free_result($rs);
    }
    echo 
    $email;
    ?>

  3. #3
    SitePoint Enthusiast Davve's Avatar
    Join Date
    Jan 2002
    Location
    Norrkoping, SWEDEN
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks!

    Though I don't understand what the if is doing there. I just removed it and know it works.
    PHP Code:
    $sql "SELECT epost FROM user2 WHERE userid = '$uid'";
    $rs=mysql_query($sql);
    $row=mysql_fetch_array($rs);
    $email $row['epost'];
    mysql_free_result($rs); 
    David Andersson Davve
    -MSc in Media Technology and Engineering:
    Working at AdLibris

  4. #4
    SitePoint Zealot
    Join Date
    Dec 2001
    Location
    Canada
    Posts
    174
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php
    $sql 
    "SELECT epost FROM user2 WHERE userid = '$uid'";
    if(
    $rs=mysql_query($sql) && $row=mysql_fetch_array($rs)){
       
    $email $row['epost'];
       
    mysql_free_result($rs);
    }
    else{
       echo(
    "Error: " mysql_error());
    }
    echo 
    $email;
    ?>
    The if allows you to check a condition before continuing. This is very important when you're coding. Incase the query fails, or something is wrong with mysql.

    Additionally mysql_query() returns an identifier and
    mysql_fetch_array() returns an array with the result set. Most often when you call mysql_query, mysql_fetch_array will come soon after (which was not in your original post).

    HTH,
    Kix


Bookmarks

Posting Permissions

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