Log in

View Full Version : simple SELECT FROM query



sniperman
07-26-2009, 10:33 AM
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
|-----------------------|


$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

thetestingsite
07-26-2009, 07:08 PM
You answered your own question.



$result = mysql_query ("SELECT `username`,`password` FROM `User Data` WHERE `username` = '".$username."' AND `password` = '".$password."'") or die(mysql_error());


Hope this helps.

sniperman
07-26-2009, 11:49 PM
thanks

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