Results 1 to 8 of 8
  1. #1
    Join Date
    Feb 2006
    Posts
    72

    Unanswered: New record server error

    Hello George

    I have been trying to read up on how I should insert a record into a database, and then clicking on another ASP file which should show me the inserted record in place.

    I have three asp files. One with an 'insert' text box, then a file which processes the actual insertion, and then a 'show' records file.

    The form itself contains the following line:

    <p><input type="submit" value="Submit"><input type="reset" value="Reset"></p>

    while the code for the asp file which processes my insert request is this:

    <%
    Response.Buffer = true
    dim cnn,rst
    set cnn = Server.CreateObject("ADODB.Connection")
    set rst = Server.CreateObject("ADODB.RecordSet")

    cnn.Open "driver={Microsoft Access Driver (*.mdb)};DBQ=D:\business\form.mdb;"
    sqltext = "SELECT * FROM Enquiries"
    rst.Open sqltext,cnn,3,3

    dim Enquiries, Fullname,Sex,Country,Hobbies,DateofBirth,ip,Date

    Fullname = Request.Form("Fullname")
    Sex = Request.Form("Sex")
    Country = Request.Form("Country")
    Hobbies = Request.Form("Hobbies")
    DateofBirth = Request.Form("DateofBirth")
    ip = Request.Form("IpAddr")
    Date = Request.Form("Date")

    if Fullname = "" then
    error = "You have not entered your correct name."
    Response.Write error
    Response.End
    end if

    rst.AddNew
    rst("Fullname") = Fullname
    rst("Sex") = Sex
    rst("Country") = Country
    rst("Hobbies") = Hobbies
    rst("DateofBirth")
    rst("IpAddr") = link
    rst("Date") = Date
    rst.update

    'Lets redirect the user back to where they came from
    Response.Redirect "addit.asp"
    %>

    There seems to be a problem with this processing code because I am getting the following error:

    Wrong number of arguments or invalid property assignment

    /insert2/add.asp, line 39

    There is no word 'Function' in there, I know, but the script does contain the AddNew instruction.

    Have you any thoughts on this?

    Thank you.

    Steve

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Hey Steve,
    I'm afraid I've not been quite as active as I normally am on the forums, so I've missed our previous topic.

    However, it does seem that you've made a lot of headway on your own - so well done!

    What is on line 39 of add.asp?
    George
    Home | Blog

  3. #3
    Join Date
    Feb 2006
    Posts
    72
    Hello again George

    Well, I suppose this time of year is always quite busy.

    Line 39 is:

    Hobbies = Request.Form("Hobbies")

    That is, if I include everything <%> signs, spaces, etc.

    I have checked in my form and the form field is definitely called Hobbies. And I have checked the database and the form field does say Hobbies, also.

    Thanks again for any help.

    Cheers

    George

  4. #4
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    What happens if you comment out the lines related to Hobbies - do you get any more errors?
    George
    Home | Blog

  5. #5
    Join Date
    Feb 2006
    Posts
    72
    Hello George

    If I do that I get the following:

    Wrong number of arguments or invalid property assignment

    /insert2/add.asp, line 34

    which refers to:

    rst("Hobbies") = Hobbies

    if I then comment out that line, I get:

    Wrong number of arguments or invalid property assignment

    /insert2/add.asp, line 34

    All mind boggling!

    Steve

  6. #6
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    <%
    Response.Buffer = true
    dim cnn,rst
    set cnn = Server.CreateObject("ADODB.Connection")
    set rst = Server.CreateObject("ADODB.RecordSet")
    
    cnn.Open "driver={Microsoft Access Driver (*.mdb)};DBQ=D:\business\form.mdb;"
    sqltext = "SELECT * FROM Enquiries"
    rst.Open sqltext,cnn,3,3
    
    dim Enquiries, Fullname,Sex,Country,Hobbies,DateofBirth,ip,Date
    
    Fullname = Request.Form("Fullname")
    Sex = Request.Form("Sex")
    Country = Request.Form("Country")
    Hobbies = Request.Form("Hobbies")
    DateofBirth = Request.Form("DateofBirth")
    ip = Request.Form("IpAddr")
    Date = Request.Form("Date")
    
    'Prove that we are assigning the correct values
    Response.Write("FullName: " & FullName)
    Response.Write("Sex : " & Sex)
    Response.Write("Country : " & Country)
    Response.Write("Hobbies: " & Hobbies)
    Response.Write("DateofBirth : " & DateofBirth)
    Response.Write("Date : " & Date)
    
    'Once we're sure we have the right values we can start uncommenting this,
    'adding a single field at a time until we're happy that each one works.
    'rst.AddNew
    'rst("Fullname") = Fullname
    'rst("Sex") = Sex
    'rst("Country") = Country
    'rst("Hobbies") = Hobbies
    'rst("DateofBirth")
    'rst("IpAddr") = link
    'rst("Date") = Date
    'rst.update
    
    'Lets redirect the user back to where they came from
    Response.Redirect "addit.asp"
    %>
    Oh and amend the highlighted text too
    George
    Home | Blog

  7. #7
    Join Date
    Feb 2006
    Posts
    72
    Hello George

    Many thanks for your valuable posts.

    I think I may now have it working. If you complete the form here:

    http://stevehigham59.7host.com/w3Test/inputForm.html

    you will be able to see your added record here:

    http://stevehigham59.7host.com/w3Test/addShow.asp

    I have also checked the database and the entry has been added.

    The script does not check for errors - if somewhere leaves a field blank, for instance - but you have posted something before on that which I have saved, so I will go back to see about adding a little extra script to capture errors.

    A lot of this is down to you, so I am grateful.

    Best Christmas cheers!

    Steve

  8. #8
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Wahey! I'm so glad you got this working - keep up the good work and read the monkeys out of w3schools!

    As always, if you need more help, post back here

    Make sure you read up on SQL Injectionand test, test, test!!

    Good luck sir
    George
    Home | Blog

Posting Permissions

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