Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2005
    Posts
    13

    Unanswered: SQL insert help using ASP

    I have an Oracle Database called testing.

    The database consists of two fields, firstname and surname.

    All I am trying to do is simply insert data into the fields using a form in ASP.

    The code I have is listed below - however it does nothing. It's driving me mad, any help is greatly appreciated. I think the problem is with the sql= insert ... part.

    -----------------------------------------------------------------
    <html>
    <body>

    <form action="insert.asp" method="post">
    Firstname <input type="text" name="Firstname" size="20">
    Surname <input type="text" name="Surname" size="20">
    <input type="submit" value="Submit">
    </form>

    <%

    dim testing
    Dim objConnection
    Dim objRecordset

    firstname=Request.Form("firstname")
    surname=Request.Form("surname")


    If testing<>"" Then

    Set objConnection = Server.CreateObject("ADODB.Connection")

    With objConnection
    .ConnectionString = "Provider=MSDAORA.1;Password=21323;User ID=21321;Data Source=stora;Persist Security Info=True"
    .Open

    sql="insert into testing (FIRSTNAME, SURNAME) " & _ values ("firstname ","surname")

    Response.Write "<BR> sql.=" & sql & "<BR> <BR>"

    Set objRecordset = .Execute(sql)


    End With

    End If

    Set objConnection = Nothing
    Set objRecordset = Nothing

    %>
    </body>
    </html>

  2. #2
    Join Date
    Oct 2005
    Posts
    178
    The variable "testing" is blank when your script runs. YOur if statement sees this and end it without going through the data retieval

    YOu just defined your variable "testing" and initially it is null
    Then in your following statements you used it in your IF statement.. that if it's not "" , do the following routine, Since it is "" the following routines are bypassed. That's why nothing was happening when executed.
    Last edited by fredservillon; 11-23-05 at 21:13.

  3. #3
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    Code:
    firstname=Request.Form("firstname")
    surname=Request.Form("surname")
    Requests are case sensitive... you need this
    Code:
    firstname=Request.Form("Firstname")
    surname=Request.Form("Surname")
    you also wil have a problem with this line...
    Code:
    sql="insert into testing (FIRSTNAME, SURNAME) " & _ values ("firstname ","surname")
    you need something like...
    Code:
    sql="insert into testing (FIRSTNAME, SURNAME) " & _ 
        "values ('" & firstname & "','" & surname & "')"
    You will need to do something the take care of the ' character that is in some peoples names....

Posting Permissions

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