| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

12-05-07, 07:40
|
|
Registered User
|
|
Join Date: Feb 2006
Posts: 51
|
|
|
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
|
|

12-05-07, 07:55
|
|
www.gvee.co.uk
|
|
Join Date: Jan 2007
Location: UK
Posts: 10,156
|
|
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?
|
|

12-05-07, 09:11
|
|
Registered User
|
|
Join Date: Feb 2006
Posts: 51
|
|
|
|
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
|
|

12-05-07, 10:24
|
|
www.gvee.co.uk
|
|
Join Date: Jan 2007
Location: UK
Posts: 10,156
|
|
What happens if you comment out the lines related to Hobbies - do you get any more errors?
|
|

12-05-07, 10:49
|
|
Registered User
|
|
Join Date: Feb 2006
Posts: 51
|
|
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
|
|

12-08-07, 08:46
|
|
www.gvee.co.uk
|
|
Join Date: Jan 2007
Location: UK
Posts: 10,156
|
|
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 
|
|

12-12-07, 04:05
|
|
Registered User
|
|
Join Date: Feb 2006
Posts: 51
|
|
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
|
|

12-18-07, 17:32
|
|
www.gvee.co.uk
|
|
Join Date: Jan 2007
Location: UK
Posts: 10,156
|
|
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 
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|