www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] How do I find info in a determined row?

  1. #1
    Join Date
    Jul 2004
    Location
    Wisconsin
    Posts
    188

    resolved [RESOLVED] How do I find info in a determined row?

    I am trying to generate an email to a user in a database. The database has the user's username as a column called "user" and their email address in a column called "email". When I submit a form, I have their username already because I am assigning a project to them. What I want to then do is search the database for their username and then grab their email address and assign it to the $email variable. Here is what I have so far but it will not output the email (I'm echoing for testing purposes):
    PHP Code:
    //email the assigned person
       
    global $database;
       
    $q "SELECT * FROM users WHERE username = $projectassigned";
       
    $result $database->query($q);
       
    $row $_GET['email'];
       
    $email $row['email'];
       echo 
    "<br /> Username: $projectassigned <br />";
       echo 
    "Email is: $email <br />"
    Any help you can provide to get this to work how I would like it to is greatly appreciated.

  2. #2
    Join Date
    May 2010
    Posts
    123
    You are on the right lines.
    $result = $database->query($q); < i have never seen this done before so i will show you how i do it.
    PHP Code:
    $q "SELECT * FROM users WHERE username = $projectassigned"
    $result mysql_query($q);
    $information mysql_fetch_assoc($result);
    $email $information['email'];
    echo 
    $email
    That should work

  3. #3
    Join Date
    Jul 2004
    Location
    Wisconsin
    Posts
    188
    aha! Thank you. I got it to work with one tiny modification to what you showed me.

    PHP Code:
    $q "SELECT * FROM users WHERE username = '$projectassigned'"
    $result mysql_query($q); 
    $information mysql_fetch_assoc($result); 
    $email $information['email']; 
    echo 
    $email
    Added the ' ' around $projectassigned.

    Cheers!

  4. #4
    Join Date
    May 2010
    Posts
    123
    Quote Originally Posted by drumbum360 View Post
    Added the ' ' around $projectassigned.

    Cheers!
    Woops yeah lol sorry I forgot about them.
    Good job!

  5. #5
    Join Date
    May 2010
    Posts
    123
    BTW you should so some research into SQL injection attacks, you could be open to vulnerabilities.

    mysql_real_escape_string(); helps. Some googling around now will prevent issues later.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles