# php, mysql, record lookup



## britishgov (Nov 11, 2004)

hi, probably a newbie question but i need the help!

i have a form, db and table setup for this and thats fine

i need some php code that looks for the output of the form which is for example $username from a table from a specific field, eg find the record where this field contains $username

then i want it to output a different field from the same record

not sure if that makes sense, if you need any more explaining please ask
any help apreciated

Sam


----------



## gamerman0203 (Oct 28, 2005)

After connecting to the database put this code in:


```
//database connection info here

$username = $_REQUEST['form_username_field_name']; //assign form data to variable
$query = mysql_query("SELECT * FROM tablename WHERE username = '{$username}'") or die(mysql_error()); //query database for username entered in form
$row = mysql_fetch_assoc($query); //assign db info to variable
if($row['username']!=""){ //check to see if the query returned any information
   echo $row['other_field_you_want_to_display']; //if yes, display the other field you want to show
}else{
   blah //If no, do something else
}
```
Hope this helps.


----------



## britishgov (Nov 11, 2004)

thats great, thanks alot

Sam


----------

