Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiuse access on the same database!

Status
Not open for further replies.

codemano

Programmer
Jan 8, 2001
1
AE
Hi Dear
I wanna make a simple Website that consists of two pages; the first page will ask the user about his/her ID and Password. When the user clicks Enter in the first page, this will take him/her to the second page. In the second page, the user can edit his/her own data according to his/her login information in the database.

The problem is that more than one user can access the site and the database simultaniously. So what shall I use for this? Sessions or what?

Please, write me a simple sample of code if you can.
Thank you.
 
Codemano, first of all, stop calling me Dear :).
Second, the internet is all about more than one person accessing a site and a database.... :) It shouldn,t be a problem.
In brief (I'm not going to write the full app for you ;-) ), what you should do is have a first page where the user enters a username and password. In the second page, verify this by running a query that is something like this:

SELECT *
FROM Users
WHERE (Username='#FORM.username#'
AND Password='#FORM.password#')

Then, check if recordcount is greater than 0 (which means the user exists) and set the Session.UserId:
<cfif myquery.recordcount GT 0>
<cfset Session.UserId=myquery.userid>
<cfelse>
<h1>Not authorized!</h1>
</cfif>

Now, the database can only be opened if there is a Session.UserId for the user:

<cfif IsDefined(&quot;Session.UserId&quot;)>
<cfquery name=&quot;MyQuery2&quot;>
SELECT *
FROM Table2
WHERE UserId=#Session.UserId#
</cfquery>
</cfif>

Make sure you activate session-management in all the pages wehere you use Session variables:
<cfapplication name=&quot;MyKillerApp&quot; sessionmanagement=&quot;Yes&quot; setclientcookies=&quot;Yes&quot;>

Turned out I wrote half of the app for you... Hope this helps anyway.


<webguru>iqof188</webguru>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top