Osai22;10975022 wrote:Hello crimsonlung,
Thanks for your help, what exactly I want to do is to write a code that can query the database as soon as a client logs in. for example, if you have a table with first name, last name, date of birth, country of origin, when a user come to the login form and enter his username and password and clicks login, once the user is logged on, he or she will see all his details on that page.
I do not know if you understand what I mean?
Oh, this is very easy. I am working on a website that is doing exactly what your asking. To see an example, go to www.grademyvoice.com and register, then click on "my profile" then click on "edit account info"
You will see that its displaying all the information that you submitted at registration.
On my registration page, I use $_SESSION to carry the login cookie over, you can read about sessions. HERE
You can do the same thing when a user logs in. Just carry the login cookie over. I suggest you play around with $_SESSION because it is necessary for what you are trying to do.
After that, you can just query the database based on that $_SESSION data. Here is an example:
$result = mysql_query("SELECT * FROM members WHERE username = '$_SESSION[login]'") or die("could not query db");
$array = mysql_fetch_assoc($result) or die("could not copy array results");
So in this example, I am using PHP to pull the login name out of the session, and query based on that login name and then throw that line of data from SQL into an array. This way I can pull out the data from that array very easily into a HTML field like so:
<table border="1">
<tr>
<th>Main Account Info</th>
<td><input name="first" type="text" id="first" value="<?php echo $array[First];?>"><br>
First Name<br></td>
<td><input name="last" type="text" id="last" value="<?php echo $array[Last];?>"><br>
Last Name<br></td>
<td><input name="email" type="text" id="email" value="<?php echo $array[Email];?>"><br>
Email<br></td>
</tr>
</table>
So the output of this will be 3 fields that display the rows of data from the database.
If you want a simpler output, just echo:
<?php
echo $array[Last] . ", ";
echo $array[First] . "<br>;
echo $array[Email];
?>
This example will produce:
John, Do
John@gmail.com
Hope this helps.