Results 1 to 3 of 3

Thread: simple SELECT FROM query

  1. #1
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    118
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default simple SELECT FROM query

    Could someone help with a simple MySQL request. I seem to be having trouble selecting from more than one field in the same table.

    TABLE: User Data
    |-----------------------|
    username | password
    |-----------------------|

    Code:
    $result = mysql_query ("SELECT `username` FROM `User Data`")
    or die(mysql_error());  
    
    $row = mysql_fetch_row($result); // converts the result into an array
    
    mysql_close($link);
    
    echo $row[0] ;
    This snip of code works fine to return one value but I want to select the 'username' and 'password' columns FROM 'user data' WHERE 'username' = '$username' AND 'password' = '$password'

    ... in one query.

    the $username $password variables are delivered via query string.


    THanks

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    You answered your own question.

    Code:
    $result = mysql_query ("SELECT `username`,`password` FROM `User Data` WHERE `username` = '".$username."' AND `password` = '".$password."'") or die(mysql_error());
    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Apr 2009
    Location
    Sydney, Australia
    Posts
    118
    Thanks
    16
    Thanked 1 Time in 1 Post

    Default

    thanks

    i tend to have a habit of answering my own questions. getting the right syntax is the problem.

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
  •