retrieve information from database
Moderator: General Moderators
-
NJ Termite
- Forum Newbie
- Posts: 6
- Joined: Fri Aug 30, 2002 11:59 pm
retrieve information from database
i need to retrive information from my database, table user,
i need it to get the fields for that user, like name, address and print it to a page. Any Sugesstions? im fairly new to php
Thanks,
Mark
i need it to get the fields for that user, like name, address and print it to a page. Any Sugesstions? im fairly new to php
Thanks,
Mark
i.e.http://www.phpcomplete.com/content.php?id=3
or http://www.webmasterbase.com/article/627
or search this database
or http://www.webmasterbase.com/article/627
or search this database
-
NJ Termite
- Forum Newbie
- Posts: 6
- Joined: Fri Aug 30, 2002 11:59 pm
thanks for the link, one question.
how could i retrive information from just one row, say if i have 4 fields with :
---------------------------------------------------------
field1 field2 field3 field4
row1 termite password Mark Mattie
row2 PDog mypass John Doe
row3 Mary108 marypass Mary Jane
----------------------------------------------------------
if the user name(field1) and password(field2) match then it wll print out First name(field3) and Last name(field3)?
example:
someone types in
njtermite(field1) password(field2) then i have the user name and passoword in variables, since they match it will print out Mark(field3 and Mattie(field4)
thanks,
mark
how could i retrive information from just one row, say if i have 4 fields with :
---------------------------------------------------------
field1 field2 field3 field4
row1 termite password Mark Mattie
row2 PDog mypass John Doe
row3 Mary108 marypass Mary Jane
----------------------------------------------------------
if the user name(field1) and password(field2) match then it wll print out First name(field3) and Last name(field3)?
example:
someone types in
njtermite(field1) password(field2) then i have the user name and passoword in variables, since they match it will print out Mark(field3 and Mattie(field4)
thanks,
mark
Here it is:
Here's the PHP code that will print out the field 3 and field 4.
Code: Select all
SELECT field3,field4 FROM table_name WHERE field1 = 'termite' AND field2 = 'password'Code: Select all
<?php
mysql_connect("host","user","password") or die("Fail to establish connection with MySQL");
mysql_select_db("db") or die("Fail to select a database");
$sql = "SELECT field3,field4 FROM table_name WHERE field1 = 'termite' AND field2 = 'password'";
$result = mysql_query($sql);
if(mysql_num_rows($result) == 0) { echo "Invalid password"; }
$row = mysql_fetch_array($result);
echo $rowї"field3"];
echo $rowї"field4"];
?>-
NJ Termite
- Forum Newbie
- Posts: 6
- Joined: Fri Aug 30, 2002 11:59 pm
-
NJ Termite
- Forum Newbie
- Posts: 6
- Joined: Fri Aug 30, 2002 11:59 pm
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
If $row contained field1, field2 and field3 elements then
would create the variables $field1, $field2, $field3.
Mac
Code: Select all
extract($row);Mac
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
Code: Select all
$MyFirstField = $rowї'field1'];Mac