Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Mar 2007
    Location
    Florida
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem with displaying a correct info from dropdown

    I've generated a dynamic dropdown populated from my database on a web form which is working fine. The problem is that what is being entered into the database is the LeagueID of the first LeagueID written to the database by another user, (ie: first LeagueID record was 6 and no matter which league is selected from the dropdown, 6 is written to the database). When I print the SQL, all of the other field info is correct. Any ideas?

    Code:
    <%   
    'declare your variables
    	dim Your_UserName
    	Your_UserName = ("UserName")
    	dim Your_LeagueName
    	Your_LeagueName = ("LeagueName")
    	dim Your_Week
    	Your_Week = ("Week")
    	dim Your_LaneNumber
    	Your_LaneNumber = ("LaneNumber")
    	dim Your_Game1
    	Your_Game1 = ("Game1")
    	dim Your_Game2
    	Your_Game2 = ("Game2")
    	dim Your_Game3
    	Your_Game3 = ("Game3")
    Dim sConnString, connection, sSQL
    'Receiving values from Form, assign the values entered to variables
    Your_LeagueID = Request.Form("LeagueID")
    Your_Week = Request.Form("Week")
    Your_LaneNumber = Request.Form("LaneNumber")
    Your_Game1 = Request.Form("Game1")
    Your_Game2 =Request.Form("Game2")
    Your_Game3 =Request.Form("Game3")
    
    sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _ 
    "Data Source=" & Server.MapPath("../db/BBAMstats.mdb") 
    'create an ADO connection object 
    Set connection = Server.CreateObject("ADODB.Connection")
    
    'Open the connection to the database
    connection.Open(sConnString)
    
    'declare SQL statement that will query the database 
    Dim rs,sqlInsert,your_userID,your_leagueID
    sqlInsert = "SELECT Users.UserID, BSA_Leagues.LeagueID FROM Users, BSA_Leagues WHERE Cust_UserName='"&Request.Cookies("UserName")&"'"
    
    Set rs = server.CreateObject("Adodb.Recordset")
    rs.open sqlInsert,connection,3
    your_userID=rs("UserID")
    your_LeagueID=rs("LeagueID")
    rs.close
    set rs=Nothing
    
    sSQL = "INSERT INTO BSA_STATS (UserID, LeagueID, Week, LaneNumber, Game1, Game2, Game3) values ("& your_userID &"," & _
    Your_LeagueID & "," & Your_Week & "," & Your_LaneNumber & "," & Your_Game1 & "," & Your_Game2 & "," & Your_Game3 & ")" 
    Response.Write sSQL
    Response.End
    'define the connection string, specify database
    'driver and the location of database
    'execute the SQL 
    connection.execute(sSQL)
    
    response.write "Your scores have been successfully recorded."
    'Done. Close the connection object
    connection.Close
    Set connection = Nothing
    %>
    When I print the SQL all of the information is correct, with the exception of the LeagueID.
    Any help would be greatly appreciated.
    Last edited by mack1604; 03-05-2007 at 05:06 PM. Reason: change in code

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    You set Your_LeagueID as this:
    Code:
    Your_LeagueID = Request.Form("LeagueID")
    Then later in the code, you set it again with new value overwriting the old one:
    Code:
    your_LeagueID=rs("LeagueID")
    So when you do an Insert, it will take the last value which is the original value in the database. So league id won't change.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Mar 2007
    Location
    Florida
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That was the problem. Thanks so much. I've been staring at this code for the last couple of days and just couldn't see it. You're a life saver. Thanks again. I gave you points and nominated you.
    Last edited by mack1604; 03-05-2007 at 05:54 PM.

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Glad to be of help to you mack1604.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •