ASP and MSAccess Insert Help
Results 1 to 3 of 3

Thread: ASP and MSAccess Insert Help

  1. #1
    Senior Member
    Join Date
    Jun 2002
    Posts
    102

    ASP and MSAccess Insert Help

    I'm messing around with ASP a little bit since I've got php down. Well here it goes
    I'm using a msaccess database with a dsn connection. The html form has text boxes on it
    for name, zip, address, phone number. In the db1.mdb there are 2 tables one for storing the name and one for storing the other information. I can't seem to get the correct syntax to
    insert the html form into the database. So how would I do this? Insert the data from the forms
    into the database?

    Heres what I've got so far

    Code:
    <%
        Dim Conn
      
        Dim SqlName
        Dim SqlAddress
        
        strName = Request.Form("txtName")
        strAddress = Request.Form("txtaddress")
        strCity = Request.Form("txtCity")
        strState = Request.Form("txtState")
        strZip = Request.Form("txtZip")
        strPhone = Request.Form("txtPhone")
        strEmail = Request.Form("txtEmail")   
       
        Set Conn = Server.CreateObject("ADODB.Connection")
        
        Conn.Open ="DSN=db1.mdb"
    
    
        SqlName="INSERT INTO Name(Name) Values('" & strName '")"
        Conn.Execute(SqlName)
        
        SqlAddress="INSERT INTO Address(Address,City,State,Zip,Phone,Email) VALUES('" & strAddress & '","' & strCity & '","' & strState & '","' & strZip & '","' & strPhone & '","' &   strEmail '")"
        Conn.Execute(SqlAddress)
    
        
       %>
    I'm more of a mySQL person but it's the syntax or how I might insert the data from the html forms into the the database and put it in the correct tables and rows.
    Good Grief

  2. #2
    Member
    Join Date
    Jul 2002
    Posts
    46
    The problem may be in your single / double quotes (?)
    try:


    SqlName="INSERT INTO Name(Name) Values('" & strName & "')"
    Conn.Execute(SqlName)

    SqlAddress="INSERT INTO Address(Address,City,State,Zip,Phone,Email) VALUES('" & strAddress & "','" & strCity & "','" & strState & "','" & strZip & "','" & strPhone & "','" & strEmail "')"
    Conn.Execute(SqlAddress)

  3. #3
    Senior Member
    Join Date
    Jun 2002
    Posts
    102
    yeap it was. I found an example using a guestbook it showed how to do it. I just copied and pasted what they had and changed the variables to mine. All those quotes get confusing. But it's working now.
    Good Grief

Posting Permissions

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