-
This damn page is giving me a headache and i need some help to get the thing up and running so could some one please help me out. This is for a used car page and what i need it to do is add new/update/delete. i have included some debugging code but all that is telling me that it it sorat working but not 100%. Heres the deal I can add a new and modify and existing record but when i do that i get errors out of nowhere. addning new doesn't refresh the list to show the new listing (ERROR #1) and and the form disappears after you addnew/modify a record (ERROR #2). I will include the URL for you to get a visual www2.shaganappi.com/pages/newlayout.asp. PLEASE HELP ME I AM DYING!
<%
Dim dbData 'connection to database (ADODB.Connection)
Dim rsData 'recordset to store cars in the dB
Dim strSQL
Dim rsOptions 'car options
Dim CategoryID
Dim VehicleID 'gets proper information related to selection
Dim numincol '
Dim i 'counter
Dim rsCar
Dim rsOption
Dim a
CategoryID = 0
VehicleID = 0
If Request.Form("CategoryID") <> vbNullString Then CategoryID = Request.Form("CategoryID")
If Request.Form("VehicleList") <> vbNullString AND Request.Form("Section") = vbNullString Then VehicleID = CLng(Request.Form("VehicleList"))
'Connection to Database
Set dbData = Server.CreateObject("ADODB.Connection")
dbData.Open Application("DSN")
'Connection to Recordsets
strSQL = " SELECT used_options.*, (SELECT CarID from used_car_options where OptionID = used_options.ID and CarID= " & VehicleID & ") as Exist"
strSQL = strSQL & " from used_options"
strSQL = strSQL & " Order by Description"
Set rsOptions = Server.CreateObject("ADODB.Recordset")
rsOptions.Open strSQL, dbData, 1, 3
strSQL = "SELECT * From used_cars"
strSQL = strSQL & " LEFT JOIN used_category ON used_cars.CategoryID = used_category.ID"
strSQL = strSQL & " LEFT JOIN used_car_options ON used_cars.CarID = used_car_options.CarID"
strSQL = strSQL & " LEFT JOIN used_options ON used_car_options.OptionID = used_options.ID"
strSQL = strSQL & " WHERE used_cars.CarID = " & VehicleID
if Request.Form("save")="save" then
Response.Write "Save request received
"
if Request.Form("year")<>vbnullstring and Request.Form("make")<>vbnullstring and Request.Form("model")<>vbnullstring then
Response.Write "Save request valid
"
set rsData=server.CreateObject("ADODB.Recordset")
rsData.Open "SELECT * FROM used_cars WHERE CarID = " & Request.Form("VehicleList"),dbData,1,3
if rsData.EOF then
rsData.AddNew
Response.Write "Adding new car...
"
Else
Response.Write "Modifying existing car...
"
End If
rsData.Fields("year")=clng(Request.Form("year"))
rsData.Fields("make")=(Request.Form("make"))
rsData.Fields("model")=(Request.Form("model"))
rsData.Fields("color")=(Request.Form("color"))
if Request.Form("Price")<>vbnullstring then rsData.Fields("Price")=ccur(Request.Form("Price"))
if Request.Form("kms")<>vbnullstring then rsData.Fields("Kms")=clng(Request.Form("kms"))
rsData.Update
carID = rsData.Fields("CarID")
Response.Write "rsData number " & carID & " updated...
"
rsData.Close
set rsData=nothing
end if
elseif Request.Form("save")="delete" then
if clng(Request.Form("VehicleList")) > 0 then
dbData.Execute "DELETE FROM used_car_options WHERE CarID = " & Request.Form("VehicleID")
dbData.Execute "DELETE FROM used_cars WHERE CarID = " & Request.Form("VehicleID")
end if
end if
%>
this code below produces error #2 on submit
<font face="arial" size="2">Make</font> <input type="text" name="make" value="<%If CarID <> vbNullString then Response.Write rsData.Fields("Make")%>">
-
The problem with adding a new record may be as simple as a misspelled object reference on your recordset. When I try to add a record it says object required which could just be the recordset misspelled. The line the error occurs on is 351. Obviously you didn't post the entire page of code cuz there's only about 70 or so lines in your post so I can't tell which one is your problem, but check around line 351.
-
kinda sorta
Monte96,
the problem with the page adding new will add but wont show up in the list (???) problem 1... problem 2 if you want to edit a record the form gets screwed up with this line <font face="arial" size="2">Make</font> <input type="text" name="make" value="<%if VehicleID <>0 then Response.Write rsData.Fields("make")%>">.
the form should populate either the list with the new value or the form the the values to edit but its not doing what it should. I know that it is saving the records by using the debugging code but why it is giving me object required error on that line (above) is beyond me
rsData stores the cars in the db???...
it just doesnt make sense to me whatsoever
-
follow up
if i change the line 237 to this instead
<font face="arial" size="2">Make</font> <input type="text" name="make" value="<%if selected then Response.Write rsData.Fields("make")%>">
using selected then the form doesnt give me the error but it doesn't populate?