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 15 of 15
  1. #1
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    inserting data to a database

    hi all,

    i have managed to get rid of all the error messages in the code but still it is not putting data into database
    any idea???

    <%@ Language = "VBScript"%>
    <%


    'Declare all local variables
    dim conn
    dim rs
    dim strconn
    dim strSQL
    Dim strCustomer_Name
    Dim strCustomer_Address
    Dim strCustomer_Postcode
    Dim strCustomer_Phonenumber
    Dim strCustomer_Email


    strCustomer_Name = Request.Form("Customer_Name")
    strCustomer_Address = Request.Form("Customer_Address")
    strCustomer_Postcode = Request.Form("Customer_Postcode")
    strCustomer_Phonenumber = Request.Form("Customer_Phonenumber")
    strCustomer_Email = Request.Form("Customer_Email")

    If Len (Customer_Name) > 0 Then

    Set conn = Server.CreateObject("ADODB.Connection")
    'set connection string to local variable-I use a DSN-less connection
    'Need to modify just this line.Point to right path to database file.
    conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\anticus\fyp\deneme.mdb"))
    'build the sql statement based on the input from the form
    'strSQL = "INSERT INTO Customer Contact Details(Customer_Name, Customer_Address, Customer_Postcode, Customer_Phonenumber, Customer_Email ) Values('" & strCustomer_Name & "','" & strCustomer_Address & "','" & strCustomer_Postcode & "','" & strCustomer_Phonenumber & "','" & strCustomer_Email & "')
    conn.Execute(strSQL)


    conn.close
    set conn = nothing
    end if


    %>



    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>


    <form action="customer details.asp" method="post">

    <p>Your name: <input type="text" name="Customer_Name"></p>
    <p>Your address: <input type="text" name="Customer_Address"> </p>
    <p>Your postcode: <input type="text" name="Customer_Postcode"> </p>
    <p>Your Phone Number: <input type="text" name="Customer_Phone"> </p>
    <p>Your e-mail address: <input type="text" name="Customer_Email"></p>
    <input type="submit" name="Submit" value="Submit">

    <p>&nbsp;</p>
    </form>
    </body>
    </html>


    when i check the database i can't really see the datas i have inserted through the web page.

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Posts
    676
    Thanks
    1
    Thanked 0 Times in 0 Posts
    pin...
    /me doesnt just a do® this kinda stuff.../mes just a knowledge® is limited to 'comparing'...
    n' what /me does see??? is youve called your phone variable one thing 'cept in the 'formfield'??? youve got it called just a something® else...

    Dim strCustomer_Phonenumber

    strCustomer_Phonenumber = Request.Form("Customer_Phonenumber")

    n' thennn youve just a got®...
    Your Phone Number: <input type="text" name="Customer_Phone"> </p>

  • #3
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok i have changed the Phonenumber bit but I couldn't really understand what you were telling in the first few lines.

    can you pls explain more clearly?

    thanks

  • #4
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    You left out the "str" in front of strCustomer_Name in your if-statement. So, none of your DB code is executing.

    I always do error checking with some basic response.write statements. For example, put a response.write inside your if-statement to make sure it is evaluating true.

    Code:
    If Len (Customer_Name) > 0 Then 
    response.write "did this work?"
    ...
    
    end if
    Then you would look at your if-statement to see why it isn't evaluating the way you expect it and notice that the variable name is incorrect.

    Don't forget to uncomment out your SQL string also.

  • #5
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have tried adding str to the Customer_Name in my if statement. I have added this text "doe that work?" and i can't see it when i submit the form.

    I think it does not read the code after the if statement and I have no idea what causes that?

    do u have any idea?

  • #6
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Try this and see what output you get.

    Code:
    response.write "Customer Name:"&strCustomer_Name&"<br>"
    response.write "Length of Customer Name:"&Len(strCustomer_Name)&"<br>"
    
    If Len(strCustomer_Name) > 0 Then 
    response.write "testing"
    ..
    
    end if
    Hope I didn't make any typos...

  • #7
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it gives an error of which points to :

    conn.execute(strSQL)


    Microsoft OLE DB Provider for ODBC Drivers error '80040e0c'

    Command text was not set for the command object.

  • #8
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    That sounds like the if-statement is returning true and executing your database code then.

    Is your strSQL statement still commented out as in the original example? You might be executing a null string.

    Also, I never use table names with spaces in them. I think you need to surround them with square brackets.

    strSQL = "INSERT INTO [Customer Contact Details](Customer_Name, Customer_Address, Customer_Postcode, Customer_Phonenumber, Customer_Email ) Values('" & strCustomer_Name & "','" & strCustomer_Address & "','" & strCustomer_Postcode & "','" & strCustomer_Phonenumber & "','" & strCustomer_Email & "')
    edit: if you're still getting an error, do a response.write strSQL before you execute your SQL statement so we can see what SQL statement you're passing in.

  • #9
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    <%@ Language = "VBScript"%>
    <%


    'Declare all local variables
    dim conn
    dim rs
    dim strconn
    dim strSQL
    Dim strCustomer_Name
    Dim strCustomer_Address
    Dim strCustomer_Postcode
    Dim strCustomer_Phonenumber
    Dim strCustomer_Email

    strCustomer_Name = Request.Form("Customer_Name")
    strCustomer_Address = Request.Form("Customer_Address")
    strCustomer_Postcode = Request.Form("Customer_Postcode")
    strCustomer_Phonenumber = Request.Form("Customer_Phonenumber")
    strCustomer_Email = Request.Form("Customer_Email")


    If Len (strCustomer_Name) > 0 Then




    Set conn = Server.CreateObject("ADODB.Connection")
    'set connection string to local variable-I use a DSN-less connection
    'Need to modify just this line.Point to right path to database file.
    conn.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\anticus\fyp\deneme.mdb"))
    'build the sql statement based on the input from the form
    'strSQL = "INSERT INTO [Customer Contact Details](Customer_Name, Customer_Address, Customer_Postcode, Customer_Phonenumber, Customer_Email ) Values('" & strCustomer_Name & "','" & strCustomer_Address & "','" & strCustomer_Postcode & "','" & strCustomer_Phonenumber & "','" & strCustomer_Email & "')
    'Response.Write(strSQL)
    conn.execute(strSQL)

    Session("Customer_Name") = strCustomer_Name
    conn.close
    set conn = nothing

    end if



    %>



    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>


    <form action="customer details.asp" method="post"name="RegisterForm">

    <p>Your name: <input type="text" name="Customer_Name"></p>
    <p>Your address: <input type="text" name="Customer_Address"> </p>
    <p>Your postcode: <input type="text" name="Customer_Postcode"> </p>
    <p>Your Phone Number: <input type="text" name="Customer_Phonenumber"> </p>
    <p>Your e-mail address: <input type="text" name="Customer_Email"></p>


    <input type="SUBMIT" name="SUBMIT" value="SUBMIT">


    </form>
    </body>
    </html>



    this is the last form of the code and it still gives the error of
    Microsoft OLE DB Provider for ODBC Drivers error '80040e0c'

    Command text was not set for the command object.


    for

    'Response.Write(strSQL)
    this time
    i am giving u a headache

  • #10
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Don't comment out those two lines where you set strSQL equal to the your INSERT statement and where you response.write(strSQL). The first line is vital and the output will show any errors.

    strSQL = "INSERT INTO [Customer Contact Details](Customer_Name, Customer_Address, Customer_Postcode, Customer_Phonenumber, Customer_Email ) Values('" & strCustomer_Name & "','" & strCustomer_Address & "','" & strCustomer_Postcode & "','" & strCustomer_Phonenumber & "','" & strCustomer_Email & "')

    Response.Write(strSQL)

    conn.execute(strSQL)
    I don't get headaches.

  • #11
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    if i do what u told then it gives me the error:

    Microsoft VBScript compilation error '800a0409'

    Unterminated string constant

    /anticus/fyp/customer details.asp, line 33

    strSQL = "INSERT INTO [Customer Contact Details](Customer_Name, Customer_Address, Customer_Postcode, Customer_Phonenumber, Customer_Email ) Values('" & strCustomer_Name & "','" & strCustomer_Address & "','" & strCustomer_Postcode & "','" & strCustomer_Phonenumber & "','" & strCustomer_Email & "')

    is that what u were expecting?

  • #12
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Yes, that means there is a quotation mark missing at the end of that line that I didn't notice.

    strSQL = "INSERT INTO [Customer Contact Details](Customer_Name, Customer_Address, Customer_Postcode, Customer_Phonenumber, Customer_Email ) Values('" & strCustomer_Name & "','" & strCustomer_Address & "','" & strCustomer_Postcode & "','" & strCustomer_Phonenumber & "','" & strCustomer_Email & "')"

  • #13
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    this is the result after doing the changes:

    INSERT INTO [Customer Contact Details](Customer_Name, Customer_Address, Customer_Postcode, Customer_Phonenumber, Customer_Email ) Values('a','a','a','a','a')
    Microsoft OLE DB Provider for ODBC Drivers error '80004005'

    [Microsoft][ODBC Microsoft Access Driver] Operation must use an updateable query.

    /anticus/fyp/customer details.asp, line 35


    which points to:
    conn.execute(strSQL)

    hope this is the last problem

  • #14
    Regular Coder
    Join Date
    Jan 2003
    Posts
    867
    Thanks
    4
    Thanked 8 Times in 8 Posts
    Sorry I've never had that error before. If I was to guess, it sounds like a problem with permissions. You have to give everyone read/write access to the folder where your Access Database file is stored so that they can edit it. Other than that, it might have something to do with the database connection mode (which I don't personally use), but this microsoft article gives some details:

    http://support.microsoft.com/default...;en-us;q175168

  • #15
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    thanks vermy much

    it is sorted out. thi problem was beacuse just one of my folder are allowed for reading and writing which is db and my database was in another folder on the server, now i carried it to that one and it is working fine...

    brilliant


  •  

    Posting Permissions

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