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.
Page 1 of 5 123 ... LastLast
Results 1 to 15 of 64
  1. #1
    New Coder
    Join Date
    Mar 2007
    Location
    Florida
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Problem Inserting Record Into Database

    I'm not sure if the problem is in my SQL statement or my Access database relationships, but I get this error:

    Microsoft JET Database Engine error '80004005'

    You cannot add or change a record because a related record is required in table 'USERS'.

    /bsa/bsa_league_added.asp, line 95

    And of course line 95 executes the SQL. This is the entire code for the page:

    This is the code for the page:
    Code:
    <%@ Language=VBScript %>
    <% Option Explicit %>
    <%Response.Expires = -1 %>
    <%Response.ExpiresAbsolute = Now() - 1 %>
    <%Response.AddHeader "pragma", "no-cache" %>
    <%Response.AddHeader "cache-control", "private" %>
    <%Response.CacheControl = "no-cache" %>
    
    <% 
    Response.Expires = -1000
    Response.Buffer = True
    Response.Clear 
    %>
    
    <%Your_UserName = request.cookies("UserName")%>
    
    <%
    Response.Expires = -1000
    Response.ExpiresAbsolute = Now() - 1
    If request.cookies("UserName") = "" AND Session("UserName") = "" then
    	Response.Redirect ("unauthorized.asp")
    	Response.End
    End If
    %>
    
    <%
    Response.Expires = -1000
    Response.ExpiresAbsolute = Now() - 1
    If Session("UserName") = "" then
    	Response.Redirect ("unauthorized.asp")
    	Response.End
    End If
    %>
    <html>
    <head>
        <title>Bowling Score Tracker</title>
    <meta name="AUTHOR" content="James Royce">
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
    <link rel="stylesheet" href="BSAstyle.css" type="text/css">    
    </head>
    <body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
    <table align="center" width="550" cellspacing="2" cellpadding="0" border="0" style="border-width: 1px; border-style: solid; color: #1b1b1b;" bgcolor="#000000" id="container">
        <tr>
            <td align="center">        
    <table align="center" width="550" border="0" cellspacing="0" cellpadding="0" bgcolor="2a3b83">
        <tr>
            <td valign="top" align="center"  background="images/bsaheader.jpg" style="background-repeat: no-repeat">
            <img src="images/clear.gif" height="141" width="550" />        
    <table width="420" height="420" border="0" cellspacing="0" cellpadding="6" background="images/form_bg.jpg" style="border-style: solid;border-width: 1px;border-color: #ffffff;">
    	<tr>
    	<td colspan="6" align="left">
    	    <ul><li><a href="bsa_add_league.asp?UserLoggedIn=<% =Your_UserName %>" target="_top">Add Another League</a>
    	    <li><a href="bsa_default.asp?UserLoggedIn=<% =Your_UserName %>" target="_top">Enter Scores</a>
    	    <li><a href="bsa.asp?UserLoggedIn=<% =Your_UserName %>" target="_top">View Stats.</a>
    	    <li><a href="information.asp?UserLoggedIn=<% =Your_UserName %>" target="_top">My Account</a>
    	    <li><a href="loginclose.asp" target="_top">Log Out</a></li>
    	    </ul>
    	</td>
    	</tr>
      <tr>
        <td align="center" style="padding-left:6px;padding-top:6px;padding-right:6px;padding-bottom:6px;">
    <%
    'declare your variables
    	dim Your_UserName
    	Your_UserName = ("UserName")
    	dim Your_LeagueName
    	Your_LeagueName = ("LeagueName")
    	dim Your_StartingLane
    	Your_StartingLane = ("StartingLane")
    	dim Your_TeamsNumber
    	Your_TeamsNumber = ("TeamsNumber")
    	dim Your_LeagueDescription
    	Your_LeagueDescription = ("LeagueDescription")
    Dim sConnString, connection, sSQL
    'Receiving values from Form, assign the values entered to variables
    Your_LeagueName = Request.Form("LeagueName")
    Your_StartingLane = Request.Form("StartingLane")
    Your_TeamsNumber = Request.Form("TeamsNumber")
    Your_LeagueDescription =Request.Form("LeagueDescription")
    
    'declare SQL statement that will query the database 
    sSQL = "INSERT INTO BSA_LEAGUES (LeagueName, StartingLane, TeamsNumber, LeagueDescription) values ('" & _
    Your_LeagueName & "','" & Your_StartingLane & "','" & Your_TeamsNumber & "','" & Your_LeagueDescription & "')" 
    'define the connection string, specify database
    'driver and the location of database
    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)
    
    'execute the SQL 
    connection.execute(sSQL)
    
    response.write "Your league was successfully added to our database."
    'Done. Close the connection object
    connection.Close
    Set connection = Nothing
    %>
        </td>
      </tr>
    	<tr>
    		<!-- Author / Developer -->
    		<td colspan="6" align="center">
    		<img src="images/clear.gif" height="40" width="1" /><br />
    		Designed and Developed by: James Royce<br />© 2007, All rights reserved.	
    		</td>
    	</tr>
    </table>
    <br /><br /> 
            </td>
        </tr>
    </table>       
            </td>
        </tr>
    </table>        
    </body>
    </html>
    Being new to this stuff, I'm about ready to pull my hair out. Any ideas or help would be greatly appreciated.

    Here is a link to a copy of my database if anyone would like to take a look at that. http://www.bowlingballsandmore.com/downloads/BBAM.zip

  • #2
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    I think there should be a relationship problem

    -SSJ

  • #3
    New Coder
    Join Date
    Mar 2007
    Location
    Florida
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I kinda guessed that. By any chance did you take a look at the mdb file?

  • #4
    New Coder
    Join Date
    Mar 2007
    Location
    Florida
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I feel like I'm in over my head here. I'm really new at this Access stuff. I do know that the relationships that I have are necessary for another part of this application to work.

  • #5
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    This may help you..

    support.microsoft.com/kb/306269

    -SSJ

  • #6
    New Coder
    Join Date
    Mar 2007
    Location
    Florida
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry, no help. There are other portions of my application that are working just fine. It's just this particular page. And I'm pretty sure it's something that is missing or that I have to do differently with my table relationships in Access.

  • #7
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    From other portions are the Insert queries working fine??

  • #8
    New Coder
    Join Date
    Mar 2007
    Location
    Florida
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes they are working fine. I suppose it could be something I need to do in my SQL. ???
    I should clarify. The user registration is working fine as well as populating a dropdown of the user's leagues.
    Last edited by mack1604; 03-02-2007 at 07:13 AM.

  • #9
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Try to print your sql query and let me know what it is printing.

    -SSJ

  • #10
    New Coder
    Join Date
    Mar 2007
    Location
    Florida
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are you saying that I should open up a query in design view and paste this:

    Code:
    sSQL = "INSERT INTO BSA_LEAGUES (LeagueName, StartingLane, TeamsNumber, LeagueDescription) values ('" & _
    Your_LeagueName & "','" & Your_StartingLane & "','" & Your_TeamsNumber & "','" & Your_LeagueDescription & "')"
    Sorry if this sounds stupid, but I'm really new at this.

  • #11
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    After this statement write following code:

    Response.write sSQL
    Response.end

    Tell me whats the output?

    -SSJ

  • #12
    New Coder
    Join Date
    Mar 2007
    Location
    Florida
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    INSERT INTO BSA_LEAGUES (LeagueName, StartingLane, TeamsNumber, LeagueDescription) values ('TGIF (Simpson Cleanup Service)','1','20','Friday night mixed league, Friendship Lanes')

    This is the info I'm trying to write to the database and it is correct.

    Then again, maybe not totally right. Souldn't there be a reference to the user?
    Last edited by mack1604; 03-02-2007 at 07:28 AM.

  • #13
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Is there any USERS table and any of the fields from this table related to that table?


    -SSJ

  • #14
    New Coder
    Join Date
    Mar 2007
    Location
    Florida
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts
    There is the UserID

    Have you, by chance, looked at the mdb file?

    http://www.bowlingballsandmore.com/downloads/BBAM.zip

  • #15
    SSJ
    SSJ is offline
    Regular Coder
    Join Date
    Mar 2007
    Posts
    230
    Thanks
    0
    Thanked 4 Times in 4 Posts
    Give me the both table structures

    -SSJ


  •  
    Page 1 of 5 123 ... LastLast

    Posting Permissions

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