Print Page | Close Window

Adding same fields to two tables

Printed From: Web Wiz Forums
Category: General Discussion
Forum Name: Classic ASP Discussion
Forum Description: Discussion on Active Server Pages (Classic ASP).
URL: https://forums.webwiz.net/forum_posts.asp?TID=6837
Printed Date: 31 March 2026 at 4:32pm
Software Version: Web Wiz Forums 12.08 - https://www.webwizforums.com


Topic: Adding same fields to two tables
Posted By: lovelymanmk
Subject: Adding same fields to two tables
Date Posted: 29 October 2003 at 1:15pm

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----




Replies:
Posted By: zaboss
Date Posted: 30 October 2003 at 12:22am
I didn't look through your code very carefully but here are some hints:
1. In IE, turn off the "Show Friendly HTTP Errors" to see what is realy wrong with your code. The google that error and I'm sure you'll find dozenz of pages from people that run into the same trouble and come up with a solution.
2. My bet is on the date as SQL and Access handles it a little bit different (but, again, I did not look very carefully to your code).

-------------
Cristian Banu
http://www.soft4web.ro - Soft 4 web


Posted By: lovelymanmk
Date Posted: 30 October 2003 at 5:28am

Hey thanks...  I did that, Zaboss! I needed to make the following adjustment in the first step (adding to Web Wiz Forum). It worked very well.

      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
      tmpFld1 = x_UserName
      If trim(tmpFld1) & "x" = "x" Then tmpFld1 = Null
      srchFld1 = replace(tmpFld1&"","'","''")
      srchFld1 = replace(srchFld1,"[","[[]")
      srchFld1 = "'" & srchFld1 & "'"
      strsql11 = "SELECT * FROM [tblAuthor] WHERE [UserName] = " & srchFld1
      Set qrs1chk = conn.Execute(strsql11)
      If NOT qrs1chk.eof Then
      Response.Redirect "existinguser.asp"
      Response.end
      End If
      qrs1("Username") = tmpFld1
      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("Show_email") = 0
      qrs1("Attach_signature") = 0
      qrs1("Active") = 1
      qrs1("Date_format") = "dd/mm/yy"
      qrs1("Time_offset") = "+"
      qrs1("Time_offset_hours") = 0
      qrs1("Rich_editor") = 1
      qrs1("Reply_notify") = 1
      qrs1("PM_notify") = 0
      qrs1.Update
      qrs1.Close
      Set qrs1 = Nothing

The problem wasn't in date. The problem simply was in some fields that shouldn't be null!

Again, Thanks a lot



Posted By: gupta_ji
Date Posted: 30 October 2003 at 6:52am
thanks

-------------
http://www.sgrj.com" rel="nofollow - chartered accountants India , http://www.delhiprofessionals.com" rel="nofollow - accounting Outsourcing ISO Certification


Posted By: ljamal
Date Posted: 30 October 2003 at 8:50am
Question:
What happens when they change their password in either of the places? Do you have a script to keep the passwords in sync?

-------------
L. Jamal Walton

http://www.ljamal.com/" rel="nofollow - L. Jamal Inc : Web/ Print Design and ASP Programming


Posted By: fernan82
Date Posted: 30 October 2003 at 9:36am
If you don't considering all you'd have to change to make the password sync it might be much easier to mod your page to use wwf users table and made a simple script to add all the users from you script's table to the forum's...

-------------
FeRnAN
http://www.danasoft.com/">


Posted By: lovelymanmk
Date Posted: 30 October 2003 at 1:50pm

Well... what I was seeking for now is just to defete the matter of adding encryting password and hashing user name. Since that the main table doesn't use encrypting and hashing. I did it!! that was great for the first time... I don't need to make editing user name and password in one table to be changed automatically in the other table (in the same changes). Yet I confess that this would be important for future. But I don't think it would be very easy if you use two tables. But, if you make only one table, it would be easy. But for my situation, it won't be practical to make one table.

However, in my situation, Not all of the Forum Users should have a user name and password in the main table. But those who apply for the main table should be easily be able to use the forum.

I'd appreciate any comment on this or any help...



Posted By: lovelymanmk
Date Posted: 31 October 2003 at 9:20am

The version of SQL Web Wiz Forum I'm using doesn't permit changing User Name. So, in edit page, you can recall [tblAuthor] where User name = user name in the main table. and you could then apply the new values... And, the problem for editing would be solved then....



-------------
Mohamad Al-Karbi



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.08 - https://www.webwizforums.com
Copyright ©2001-2026 Web Wiz Ltd. - https://www.webwiz.net