Hi... I have a site where visitors are registering their resumes in the main database (main table). The visitors should apply a username and password to edit their details later. NOw, I've purchased Web wiz forum and I'm try to somehow merge the username and password of the main table with the forum. So, the visitors can use the same username and password they registered in the main table in the forum too. So they don't have to apply for a user name and password in the forum too. Based on this I made the code in the main add page to automatically add the same fields into the table of web wiz forum (tblAuthor). I got it work very well when I used MS Access. But when I use it on SQL it didn't work. And I've always got that this page can't be displayed. Any comment or help?!
------ Start of code ------
<!--#include file="db.asp"-->
<!--#include file="functions_hash1way.asp" -->
<!--#include file="functions_common.asp" -->
'I have modified the previous two asp files so it only does the hashing
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open xDb_Conn_Str
x_UserID = Request.Form("x_UserID")
x_UserName = Request.Form("x_UserName")
x_Password = Request.Form("x_Password")
x_FirstName = Request.Form("x_FirstName")
x_LastName = Request.Form("x_LastName")
...
...
...
' First it adds to Web Wiz Forum
strsql0 = "SELECT * FROM [tblAuthor] WHERE 0 = 1"
Set qrs1 = Server.CreateObject("ADODB.Recordset")
qrs1.Open strsql0, conn, 1, 2
qrs1.AddNew
qrs1("Group_ID") = 4
tmpFld = x_UserName
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
srchFld = replace(tmpFld&"","'","''")
srchFld = replace(srchFld,"[","[[]")
srchFld = "'" & srchFld & "'"
strsql = "SELECT * FROM [tblAuthor] WHERE [UserName] = " & srchFld
Set rschk = conn.Execute(strsql)
If NOT rschk.eof Then
Response.Redirect "existinguser.asp"
Response.end
End If
' the previous ten lines are to make sure that username is unique
qrs1("Username") = tmpFld
qrs1("Real_name") = x_FirstName & " " & x_LastName
qrs1("User_code") = userCode(x_UserName)
strSalt = getSalt(Len(x_Password))
strEncyptedPassword = x_Password & strSalt
strEncyptedPassword = HashEncode(strEncyptedPassword)
qrs1("Password") = strEncyptedPassword
qrs1("Salt") = strSalt
qrs1("Active") = True
qrs1("Date_format") = "dd/mm/yy"
qrs1.Update
qrs1.Close
Set qrs1 = Nothing
' Second it add to main table
strsql = "SELECT * FROM [maintable] WHERE 0 = 1"
Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strsql, conn, 1, 2
rs.AddNew
tmpFld = Trim(x_UserName)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
srchFld = replace(tmpFld&"","'","''")
srchFld = replace(srchFld,"[","[[]")
srchFld = "'" & srchFld & "'"
strsql = "SELECT * FROM [maintable] WHERE [UserName] = " & srchFld
Set rschk = conn.Execute(strsql)
If NOT rschk.eof Then
Response.Redirect "existinguser.asp"
Response.end
End If
' the previous ten lines are to make sure that username is unique
rs("UserName") = tmpFld
tmpFld = Trim(x_Password)
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
rs("Password") = tmpFld
...
...
...
rs.Update
rs.Close
Set rs = Nothing
conn.Close
Set conn = Nothing
Response.Clear
------ end of code ------
I've Made the following test to make sure that the SQL is working well. The result was succefull:
----start of code----
strSalt = getSalt(Len(x_Password))
strEncyptedPassword = x_Password & strSalt
strEncyptedPassword = HashEncode(strEncyptedPassword)
tmpFld = x_UserName
If trim(tmpFld) & "x" = "x" Then tmpFld = Null
srchFld = replace(tmpFld&"","'","''")
srchFld = replace(srchFld,"[","[[]")
srchFld = "'" & srchFld & "'"
strsql = "SELECT * FROM [tblAuthor] WHERE [UserName] = " & srchFld
Set rschk = conn.Execute(strsql)
If NOT rschk.eof Then
Response.Redirect "existinguser.asp"
Response.end
End If
Set rs = Server.CreateObject("ADODB.Recordset")
ssql="INSERT INTO tblAuthor (Group_ID, Username, Real_name, User_code, Password, Salt, Active, Date_format) VALUES('" & 4 & _
"','" & tmpFld & "','" & x_LastName & "','" & userCode(x_UserName) & "', '" & strEncyptedPassword & "', '" & strSalt & "','" & 1 & _
"','" & "dd/mm/yy" & "')"
Response.write(SSQL)
Response.end
----end of code----
Edited by lovelymanmk