Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Adding same fields to two tables
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Adding same fields to two tables

 Post Reply Post Reply
Author
lovelymanmk View Drop Down
Newbie
Newbie


Joined: 08 March 2003
Location: Qatar
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote lovelymanmk Quote  Post ReplyReply Direct Link To This Post Topic: Adding same fields to two tables
    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----



Edited by lovelymanmk
Back to Top
zaboss View Drop Down
Senior Member
Senior Member


Joined: 20 August 2002
Location: Romania
Status: Offline
Points: 454
Post Options Post Options   Thanks (0) Thanks(0)   Quote zaboss Quote  Post ReplyReply Direct Link To This Post 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
Soft 4 web
Back to Top
lovelymanmk View Drop Down
Newbie
Newbie


Joined: 08 March 2003
Location: Qatar
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote lovelymanmk Quote  Post ReplyReply Direct Link To This Post 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

Back to Top
gupta_ji View Drop Down
Groupie
Groupie
Avatar

Joined: 29 October 2003
Location: India
Status: Offline
Points: 70
Post Options Post Options   Thanks (0) Thanks(0)   Quote gupta_ji Quote  Post ReplyReply Direct Link To This Post Posted: 30 October 2003 at 6:52am
thanks
Back to Top
ljamal View Drop Down
Mod Builder Group
Mod Builder Group


Joined: 16 April 2003
Status: Offline
Points: 888
Post Options Post Options   Thanks (0) Thanks(0)   Quote ljamal Quote  Post ReplyReply Direct Link To This Post 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?
Back to Top
fernan82 View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 17 November 2002
Location: United States
Status: Offline
Points: 362
Post Options Post Options   Thanks (0) Thanks(0)   Quote fernan82 Quote  Post ReplyReply Direct Link To This Post 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
Back to Top
lovelymanmk View Drop Down
Newbie
Newbie


Joined: 08 March 2003
Location: Qatar
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote lovelymanmk Quote  Post ReplyReply Direct Link To This Post 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...



Edited by lovelymanmk
Back to Top
lovelymanmk View Drop Down
Newbie
Newbie


Joined: 08 March 2003
Location: Qatar
Status: Offline
Points: 29
Post Options Post Options   Thanks (0) Thanks(0)   Quote lovelymanmk Quote  Post ReplyReply Direct Link To This Post 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....

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.