-2

私は自分のプロジェクト用にこのコードを持っており、ユーザー固有のデータを表示するアカウント ページにユーザーを誘導したいと考えています。つまり、サプライヤーのリストです。セッション変数を作成する必要があることはわかっていますが、それをコードのどこに置くべきかわかりません。また、アカウント ページでユーザーを指定するコードもわかりません。誰でも助けることができますか?これが私のコードです。

<%
'Connection String
Dim Conn
'Query to be executed
Dim SQLQuery
'Recordset
Dim rs
'StudentNo Of Logged in user
Dim UserName
'Password of User
Dim Password

'Getting information from submitted form
UserName = request.form("username")
Password = request.form("password")
RememberMe = request.form("rememberme")

'If not blank Username password submitted
if UserName <> "" or Password <> "" then  

'Creating connection Object    
set Conn=server.createobject("ADODB.Connection")

'Creating Recordset Object    
set rs = Server.CreateObject("ADODB.Recordset")    

'Initialising Provider String    
connStr = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ="& Server.MapPath("database.mdb")&";"   


'Opening Connection to Database    
Conn.open  connStr        
'Query to be executed    
SQLQuery = "select * from customers_tbl where c_email = '"&UserName&"' AND c_password = '"&Password&"'"   
'Retrieving recordset by executing SQL   
set rs=Conn.execute(SQLQuery)    
'If no records retrieved    
if rs.BOF and rs.EOF then        
Response.Redirect "customerlogin.htm?username=" & UserName    
else         
'If remember me selected        
if RememberMe = "ON" then
'Writing cookies permanently            
Response.Cookies("UserName")=UserName            
Response.Cookies("Password")=Password            
Response.Cookies("UserName").Expires = Now() + 365            
Response.Cookies("Password").Expires = Now() + 365            
Response.Redirect "customeraccount.htm"
else
'writing cookies temporarily            
    Response.Cookies("UserName")=UserName            
    Response.Cookies("Password")=Password            
    Response.Redirect "customeraccount.htm"
end if        
'Closing all database connections        
Conn.Close       
rs.close          
set rs = nothing        
set Conn = nothing    
end if
else    
'Invalid User    
Response.Redirect "customerlogin.htm?UserName=blank"
end if
%>
4

1 に答える 1

0

Customers テーブルの主キーが CustomerId と呼ばれると仮定すると、次のようなものを持つことができます

if rs.BOF and rs.EOF then        
Response.Redirect "customerlogin.htm?username=" & UserName    
else
Session("CustomerId") = rs("customerid") 

次に、顧客アカウントページでクエリを実行できます

SQLQuery = "select * from customers_tbl where customerid = "&Session("CustomerId")

あなたのコードについて私が気づいた2つのこと。

まず、.asp 拡張子ではなく .htm 拡張子を持つ asp ページがあるようです。おそらく、関連する IIS 設定を変更して、.htm ページをフラットな html ではなく ASP であるかのように扱うようにしました。

次に、ODBC 接続文字列を使用しています。これは機能しますが、OLEDB ドライバーの方が速いと考えられています。

connstr = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=""& Server.MapPath("database.mdb")
于 2013-03-26T00:16:03.227 に答える