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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Why doesn't this work? (mysql stuff)

    the part that doesn't work is
    PHP Code:
    $user mysql_query("SELECT * FROM players WHERE name='$phpuser'"); 
    I THINK, because i cant
    PHP Code:
    echo $user['zone'
    or anything..

    Please help
    btw yes there are actual users in the table and stuff

    PHP Code:
    ...
    $phpuser = $_SERVER['PHP_AUTH_USER'];
    $user = mysql_query("SELECT * FROM players WHERE name='$phpuser'");
    ?>

    <html>
        <body>
            <?php
            $userzone 
    $user['zone'];
            echo 
    'php user: ' $phpuser;
                
    $q mysql_query("SELECT * FROM players WHERE zone='$userzone'");
                while(
    $i mysql_fetch_array($q))
                {
                    echo 
    $i['name'] . " is in " $i['zone'];
                }
            
    ?>
        </body>
    </html>
    If you're wondering what I'm doing then it's selecting a user based on htaccess authentication and then finding everyone in his zone..
    Last edited by hlinzi; 04-14-2012 at 08:46 PM.

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    this returns a RESOURCE
    PHP Code:
    $user mysql_query("SELECT * FROM players WHERE name='$phpuser'"); 
    to get the record you need (if there is only one record)
    PHP Code:
    $row mysql_fetch_array($user);
    echo 
    $row['zone']; 
    for multiple records use a while loop


  •  

    Posting Permissions

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