Wrox Programmer Forums
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 20th, 2004, 04:18 AM
Authorized User
 
Join Date: Sep 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mikersantiago
Default View recordset for the specific user

Please help.

I wanted to show records (computer details) for a specific user automatically when he logs in. The user accounts (i.e. username and password) are found on tbl_users of the database while computer details (i.e. Monitor, CPU, Keyboard, etc.) are found on tbl_Accountdtls.

I have 3 asp pages,

1.login.asp

<input name="user" type="text" id="user" value="guest">
<input name="password" type="password" id="password" value="guest">

2.process.asp

<%
StrUser = Request.Form("user")
%>

<%
'connection to sql server
...
SQLStmt.CommandText = "SELECT * FROM tbl_Users WHERE tbl_Users.username='" & StrUser & "'"
...
'rest of the scripts to redirect to main.asp or admin.asp for users
'and admin respectively, if username and password is correct. Or
'Response.Redirect("login.asp?Error=Incorrect username or password")
'and Response.Redirect("login.asp?Error=Admin session was time out")
'no problem here
%>

3.main.asp

<%
'the problem lies here
...
SQLStmt.CommandText = "SELECT * FROM tbl_Accountdtls, tbl_Users WHERE tbl_Accountdtls.ID=tbl_Users.ID"

'Im using the field ID to make a relationship between tbl_Accountdtls
'and tbl_Users to link the logged user to his specific computer
'recordset in the tbl_Accountdtls table.
'this is where i think i got it all wrong, i may have to use session but don't know how to go about it.
...
%>

Monitor<%=RS("AccMonitor")%>



Please help. Thank you all :)

 
Old October 20th, 2004, 06:19 AM
Authorized User
 
Join Date: Sep 2004
Posts: 11
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to mikersantiago
Default

I've modified my scripts to the ff:

--process.asp
'added the ff
Session("userID") = RS("ID")
Session("userName") = RS("username")


--main.asp
'added the ff
strUserName = Session("userName")
userID = Session("userID")

SQLStmt.CommandText = "SELECT tbl_Accountdtls.AccMonitor, tbl_Accountdtls.AccKeyboard, tbl_Accountdtls.AccMouse, tbl_Accountdtls.AccCPU, tbl_Accountdtls.AccCDRom, tbl_Accountdtls.AccModem, tbl_Accountdtls.AccPrograms, tbl_Accountdtls.AccPrinter, tbl_Accountdtls.AccOthers FROM tbl_Accountdtls, tbl_Users WHERE tbl_Users.ID =" & userID

'but still displays the first recordset in the table
'i may be getting close already, something is just wrong in the sql
'statement

Monitor<%=RS("AccMonitor")%>

Please help :)


 
Old October 20th, 2004, 06:27 AM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 683
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi,

How are the user & accounts tables related - do you have a userid field or similar in the accounts table?

You need to create a join between the tables when querying e.g.
Code:
FROM tbl_Accountdtls a INNER JOIN tbl_Users u ON a.userid = u.ID
HTH,

Chris

 
Old October 20th, 2004, 06:30 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 109
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to anubhav.kumar
Default

Greetings from me. I have just joined this forum

This is what you have written
**************************************************
SQLStmt.CommandText = "SELECT tbl_Accountdtls.AccMonitor, tbl_Accountdtls.AccKeyboard, tbl_Accountdtls.AccMouse, tbl_Accountdtls.AccCPU, tbl_Accountdtls.AccCDRom, tbl_Accountdtls.AccModem, tbl_Accountdtls.AccPrograms, tbl_Accountdtls.AccPrinter, tbl_Accountdtls.AccOthers FROM tbl_Accountdtls, tbl_Users WHERE tbl_Users.ID =" & userID
************************************************** ****

Just Make a correction as follows
[ i assume that id in tdl_accounts and userid in other table are the joining fields]
************************************************** *************
SQLStmt.CommandText = "SELECT tbl_Accountdtls.AccMonitor, tbl_Accountdtls.AccKeyboard, tbl_Accountdtls.AccMouse, tbl_Accountdtls.AccCPU, tbl_Accountdtls.AccCDRom, tbl_Accountdtls.AccModem, tbl_Accountdtls.AccPrograms, tbl_Accountdtls.AccPrinter, tbl_Accountdtls.AccOthers FROM tbl_Accountdtls WHERE tbl_Accountdtls.ID =" & session("userID")
************************************************** **************
That's it. Simple.

Anubhav Kumar
 
Old October 20th, 2004, 10:19 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi mikersantiago,
Quote:
quote:SQLStmt.CommandText = "SELECT tbl_Accountdtls.AccMonitor, tbl_Accountdtls.AccKeyboard, tbl_Accountdtls.AccMouse, tbl_Accountdtls.AccCPU, tbl_Accountdtls.AccCDRom, tbl_Accountdtls.AccModem, tbl_Accountdtls.AccPrograms, tbl_Accountdtls.AccPrinter, tbl_Accountdtls.AccOthers FROM tbl_Accountdtls, tbl_Users WHERE tbl_Users.ID =" & userID
I don't see any necessity to use tbl_Users table in the above query,as you weren't listing any of the columns from tbl_Users table. So why should that be used in FROM and WHERE clauses? Is there a column that depicts the USERID within tbl_Accountdtls? If so rephrase your last part of the query as give below.
Code:
FROM tbl_Accountdtls WHERE tbl_Accountdtls_USERID_COLUMN =" & userID
That should help you out of this.

Cheers!

_________________________
- Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
View an ado recordset in a form feets Access VBA 5 June 20th, 2007 06:19 AM
How do after i login it will display specific user PHP FAQs 0 July 20th, 2006 08:06 PM
show data for a specific user momo BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 July 17th, 2006 09:08 PM
Order a recordset by specific values SoC SQL Language 2 August 28th, 2005 08:27 PM
Selection of a Specific Recordset gmoney060 Classic ASP Basics 1 August 9th, 2004 03:33 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.