Insert into syntax error

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kisalabs
    New Member
    • Aug 2007
    • 2

    #1

    Insert into syntax error

    I have been trying to insert a new record into an access database and cannot get any of the scripts to work.. I can access the db and pull up/display records but cannot get one added. Please help. (info to be inserted comes from form)
    Code:
    Inserting Records :
    <form action="a.asp" method="post">
    	FirstName : <input type="text" name="FirstName"><br>
    	LastName : <input type="text" name="LastName"><br>
    	Email : <input type="text" name="Email"><br>
    	DateTime : <input type="text" name="DateTime"><br>
    	RequestDescription : <textarea name="RequestDescription" cols="20" rows="5"></textarea><br>
    	Rank : <input type="text" name="Rank"><br>
    	PhoneNumber : <input type="text" name="PhoneNumber"><br>
    	Section : <input type="text" name="Section"><br>
    	BuildingNumber : <input type="text" name="BuildingNumber"><br>
    	RoomNumber : <input type="text" name="RoomNumber"><br>
    	RequestType : <input type="text" name="RequestType"><br>
    	
    	
    	<input type="submit" value="submit">
    </form>
    Code:
    
    <%
    ' Declaring variables
    
    
    Dim DateTime, PhoneNumber, Rank, LastName, FirstName, Section , BuildingNumber, RoomNumber, RequestType, Email, RequestDescription, con, sql_insert
    
    
    ' A Function to check if some field entered by user is empty
    Function ChkString(string)
    	If string = "" Then string = " "
    	ChkString = Replace(string, "'", "''")
    End Function
    
    ' Receiving values from Form
    name = ChkString(Request.Form("name"))
    email = ChkString(Request.Form("email"))
    DateTime = ChkString(Request.Form("DateTime"))
    PhoneNumber = ChkString(Request.Form("PhoneNumber"))
    Rank = ChkString(Request.Form("Rank"))
    LastName = ChkString(Request.Form("LastName"))
    FirstName = ChkString(Request.Form("Section"))
    BuildingNumber = ChkString(Request.Form("BuildingNumber"))
    RequestType = ChkString(Request.Form("RequestType"))
    RequestDescription = ChkString(Request.Form("Request Description"))
    
    data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ 
    Server.MapPath("wots.mdb")
    sql_insert = ("INSERT INTO MasterTable ( Email, DateTime, PhoneNumber, Rank, LastName, FirstName, Section, BuildingNumber,  RequestType, RequestDescription) VALUES ('" & email & "', '" & DateTime & "', '" & PhoneNumber & "', '"& Rank &"' '"& LastName &"', '" & FirstName &"', '" & Section &"' '" & BuildingNumber &"' '" & RequestType & "' '" & RequestDescription &"' )")
    
    ' Creating Connection Object and opening the database
    Set con = Server.CreateObject("ADODB.Connection")
    con.Open data_source
    con.Execute sql_insert
    
    ' Done. Close the connection
    con.Close
    Set con = Nothing
    %>
  • damonreid
    Recognized Expert New Member
    • Jul 2007
    • 114

    #2
    If you place code tags around this it will be much easier to use.

    Also what version of windows/access are you running?

    Comment

    • kisalabs
      New Member
      • Aug 2007
      • 2

      #3
      MS access 2002 sp3 is on the server, MS access 2003 sp2 was used to create the DB

      Server 2003

      Comment

      Working...