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 6 of 6
  1. #1
    New Coder
    Join Date
    Jun 2010
    Posts
    71
    Thanks
    14
    Thanked 0 Times in 0 Posts

    Displaying a row depending on user

    Hey there

    I am trying to create a profile page. Where the user that is signed in will have their info displayed. Here is what I have so far: profile.php

    PHP Code:
    <?php include("tophead.php"); ?>
    <?php 
    include("header.php"); ?>
    <?php
    // Adjust MySQL connection settings...
    $username="******";
    $password "*****"
    $hostname "localhost"
    $database "******";      

    // Connect to MySQL...
    $conn mysql_connect($hostname$username$password)      or die("Connecting to MySQL failed");  
    mysql_select_db($database$conn)     or die("Selecting MySQL database failed"); 

    // Run our query, see if session username exists in session field...
    $sql="select fname,lname,email from users where username='{$_SESSION['username']}' limit 1";
    $result=mysql_query($sql,$conn);

    // Parse our results into $data (as an associative array)...
    $data=mysql_fetch_assoc($result);

    // If one row was found in the result set, username exists...
    if ($mysql_num_rows==1) {
    print 
    "Welcome, {$data['fname']} {$data['lname']}, your E-Mail address is {$data['email']}";
    }
    // Otherwise...
    else {
    print 
    "Sorry, the username {$_SESSION['username']} was not found in our database...";
    }
    ?>
    </body>
    </html>
    But when I go to the page it says:
    "Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource on line 19" which is $data=mysql_fetch_assoc($result);

    I am at a complete lost. Any help or ways to change it will help. Here is basically what I would like... the page will take the user and display their info in their row in the mysql database. Is it even possible?
    Last edited by blackrain87; 06-25-2010 at 07:05 AM.

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,537
    Thanks
    45
    Thanked 259 Times in 256 Posts
    It means the query you wrote is wrong. Depending on your DB, it might be case sensitive, so I'd start by making sure cases match up. After that, you need to sanitize your DB entry, otherwise people can really mess with your stuff.

    Without seeing how your table is setup, I can't say much else.

  • #3
    New Coder
    Join Date
    Jun 2010
    Posts
    71
    Thanks
    14
    Thanked 0 Times in 0 Posts
    http://files.newestfunny.com/uploads/1277512437.jpg

    If there is any other info you need, let me know! Also, if you know have a script that does this already, could you share?

  • #4
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,537
    Thanks
    45
    Thanked 259 Times in 256 Posts
    Heh... the table in your DB is 'user' and the table in your query is 'users'

  • Users who have thanked Keleth for this post:

    blackrain87 (06-25-2010)

  • #5
    New Coder
    Join Date
    Jun 2010
    Posts
    71
    Thanks
    14
    Thanked 0 Times in 0 Posts
    LOL WOW! Such a simple mistake. Ok, so I went to the page and now the page is blank
    It says the username does not exist like it should in case there is an error, but I was most definitely existed.

  • #6
    New Coder
    Join Date
    Jun 2010
    Posts
    71
    Thanks
    14
    Thanked 0 Times in 0 Posts
    Woot got it working! I changed the code a bit though:

    Before the line at
    PHP Code:
    $mysql_num_rows 
    Changed it to
    PHP Code:
    mysql_num_rows($result
    Thanks for all your help!


  •  

    Posting Permissions

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