Forums

PHP

This topic is locked

which user created the record

Posted 08 Oct 2005 14:38:00
1
has voted
08 Oct 2005 14:38:00 jamie b posted:
hello, i use mysql,php,dwmx

i have 2 mysql tables: tbl_user (id,usrname,realname,pwd,level)
and tbl_personnel (id, lots of fields)

in dw i created a 'insert record' form. the login page redirects the user to this personnel_form to insert new records. everything works as it should.

my question:

1. on the personnel_form, i need to display the name of the logged-in user.

2. i also need to keep track of which user created the record, as well as the date/time.

i think i need 2 more fields in the tbl_personnel table to hold the username(who inserted the record), as well as a field for the timestamp.

but i am not sure how to go about this.

any! advice please.

thank you.
jamie.

Replies

Replied 12 Oct 2005 16:04:51
12 Oct 2005 16:04:51 Roddy Dairion replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
hello, i use mysql,php,dwmx

i have 2 mysql tables: tbl_user (id,usrname,realname,pwd,level)
and tbl_personnel (id, lots of fields)

in dw i created a 'insert record' form. the login page redirects the user to this personnel_form to insert new records. everything works as it should.

my question:

1. on the personnel_form, i need to display the name of the logged-in user.

2. i also need to keep track of which user created the record, as well as the date/time.

i think i need 2 more fields in the tbl_personnel table to hold the username(who inserted the record), as well as a field for the timestamp.

but i am not sure how to go about this.

any! advice please.

thank you.
jamie.

<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>
Answer to question 1:
Ok 2 ways of doing this
1 is by using a session so basically when the user login it finds the username and password that match in you tbl_user take the user_id insert it in the session as such "$_SESSION['user'] = $user_id" and pass it on everypage that the user will access. And using the "include function" you prewrite the code in another page to find the username with the user_id and echo the data on every page

2 - This will use the same principle e.i. find the matching username and password take the user_id but this time you will have to pass it in all your link and the nyou use $_GET to retrieve the user_id and again you use the include function to check the user_id and echo the username. This process is quite complicated as you wil have to pass it to everylink. Its best to use session.

Answer to question 2:
If you use one of the steps above all you do is just add one field in your table, named "id" and then everytime the user insert a new record you take the user_id and insert it together.

Hope it helps.

Roddy

Reply to this topic