Getting errors with checkboxes on HTML form
I have a form for inputting DVDs online to my database table called DVDs. I have written the form to match all the fields in the form and have built a cfm page to send the information to called ADDDVD.cfm. This code was given to me by my previous instructor for a Web Programming course I just completed. I have several checkboxes in the form and when I try to enter data, I keep getting errors for the checkboxes. Here is the code for the data entry form:
Data Entry Form for DVDs
The Collection Input Form
Movie Title:
Director:
Main Actors:
Studio House:
Genre:
Description:
Running Minutes:
Parental Rating:
Series Flag:
Series Name:
Copy Flag:
MDL Flag:
GCL Flag:
On Loan Flag:
On Loan Date:
On Loan Name:
Requested By:
Here is the code for the ADDDVD.cfm page:
INSERT INTO DVDS
(MovieTitle, director, mainactors, studiohouse, Genre, description,
runningminutes, ParentalRating, seriesflag, seriesname, copyflag, mdlflag, gclflag, onloanflag,
onloandate, onloanname, requestorname)
VALUES
('#Form.MovieTitle#','#Form.director#','#Form.mainactors#' '#Form.studiohouse#',
'#Form.genre#', '#Form.description#', '#Form.runningminutes#', '#Form.parentalrating#',
'#Form.seriesflag#', '#Form.seriesname#', '#Form.copyflag#', '#Form.mdlflag#',
'#Form.gclflag#', "#Form.onloanflag#' '#Form.onloandate#', '#Form.onloanname#',
'#Form.requestorname#')
Add DVD Input
The error that I am getting is:
Error Occurred While Processing Request
Element SERIESFLAG is undefined in FORM.
The error occurred in C:\websites\kfandale\web173F\CFoxworthy\Securitypages\AddDVD.cfm: line 10
8 : ('#Form.MovieTitle#','#Form.director#','#Form.mainactors#' '#Form.studiohouse#',
9 : '#Form.genre#', '#Form.description#', '#Form.runningminutes#', '#Form.parentalrating#',
10 : '#Form.seriesflag#', '#Form.seriesname#', '#Form.copyflag#', '#Form.mdlflag#',
11 : '#Form.gclflag#', "#Form.onloanflag#' '#Form.onloandate#', '#Form.onloanname#',
12 : '#Form.requestorname#')
I do not have all checkboxes checked for entering data. They are set up for different scenarios concerning the DVDs. How do I get the database table to accept the data without getting this error? Do I need to do something more to the checkboxes in order to have them accepted if they are checked or not? Any help would be appreciated. Thanks.
Cori
openmind posted this at 18:07 — 17th May 2004.
He has: 945 posts
Joined: Aug 2001
OK two things wrong here.
1 - Your checkboxes do not have a value assigned to them so change this:
to this:
When you come to your query to add the data to the database you have to be handle the fact that the checkboxes may not be checked. The simplest way is to just set a default parameter:
When the form submits if this checkbox is not check the default 0 kicks in and if it is it set the parameter to 1.
Now just amend you query to add the data:
INSERT INTO DVDS
(MovieTitle, director, mainactors, studiohouse, Genre, description,
runningminutes, ParentalRating, seriesflag, seriesname, copyflag, mdlflag, gclflag, onloanflag,
onloandate, onloanname, requestorname)
VALUES
('#Form.MovieTitle#','#Form.director#','#Form.mainactors#' '#Form.studiohouse#',
'#Form.genre#', '#Form.description#', '#Form.runningminutes#', '#Form.parentalrating#',
#seriesflag#, '#Form.seriesname#', #copyflag#, #mdlflag#,
#gclflag#, #onloanflag#, '#Form.onloandate#', '#Form.onloanname#',
'#Form.requestorname#')
Two there things.
1 - Only use single apostrophes around data values when the data type is text not numbers
2 - Try and get into the hapit of using the CFQUERYPARAM tag in your queries as it speeds things up and helps secure the query against malicios users.
One last point, never show your datasource name in posts as a malicious user could use it against you when the site is live...
cgacfox posted this at 18:29 — 17th May 2004.
She has: 15 posts
Joined: May 2004
Thanks very much for your help. I have changed the checkbox info on the data entry form. Where does this statement go?
Also you suggested using CFQUERYPARAM. Is this used in place of CFQUERY? I am only going by what my instructor showed me to do. I should receive a book that I ordered called "Macromedia Coldfusion MX Web Application Construction Kit 5th Edition" by Ben Forta in a couple of days. Again thanks very much for all your help.
openmind posted this at 18:48 — 17th May 2004.
He has: 945 posts
Joined: Aug 2001
The cfparam should go immeadiatly before your query to add the data to the database.
You can find a good explanation of the cfparam tag and why you should use it here on the EasyCFM site that is packed with other ColdFusion tutorials and a very good CF forum as well...
cgacfox posted this at 19:25 — 17th May 2004.
She has: 15 posts
Joined: May 2004
I placed the CFPARAM code on the ADDDVD.cfm page above the query to add the data. I also added the code to cover the other checkboxes that could be blank. I tested and here is the new error that I am getting:
Error Occurred While Processing Request
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Syntax error (missing operator) in query expression ''Bill Paxton, Tava Smiley, James Cameron, Lewis Abernathy, Lori Johnston, Don Lynch, Ken Marschall, Charles Pellegrino ' 'Disney''.
The error occurred in AddDVD.cfm: line 24
22 : #seriesflag#, '#Form.seriesname#', #copyflag#, #mdlflag#,
23 : #gclflag#, #onloanflag#, '#Form.onloandate#', '#Form.onloanname#',
24 : '#Form.requestorname#')
25 :
26 :
I don't understand this error. It is pointing to line 24 but the above statement says that there is a syntax error and I am missing an operator. I'm confused!
openmind posted this at 21:06 — 17th May 2004.
He has: 945 posts
Joined: Aug 2001
Try getting rid of the single quotes around any queery value that deals with dates i.e. #Form.onloandate#
If this doesn't work, post your full query page with the cfparam tags and I'll have a look.
cgacfox posted this at 21:46 — 17th May 2004.
She has: 15 posts
Joined: May 2004
I removed the single quotes around onloandate and runningminutes. This still didn't work. Here is the code from the ADDDVD.cfm page. This is the page that the DVDs.html page sends info to.
INSERT INTO DVDS
(MovieTitle, director, mainactors, studiohouse, Genre, description,
runningminutes, ParentalRating, seriesflag, seriesname, copyflag, mdlflag, gclflag, onloanflag,
onloandate, onloanname, requestorname)
VALUES
('#Form.MovieTitle#','#Form.director#','#Form.mainactors#' '#Form.studiohouse#',
'#Form.genre#', '#Form.description#',#Form.runningminutes#,
'#Form.parentalrating#', #seriesflag#, '#Form.seriesname#', #copyflag#, #mdlflag#,
#gclflag#, #onloanflag#, #Form.onloandate#, '#Form.onloanname#',
'#Form.requestorname#')
Add DVD Input
This is turning out to be more tricky that I thought it would. Thanks.
cgacfox posted this at 01:42 — 19th May 2004.
She has: 15 posts
Joined: May 2004
I received my book that I bought on ColdFusion today but I can't really find anything that points to what my error is. I originally saved the input form page as an HTML page but changed it to a CFM page. That didn't help anything. I still get the same error. Should I post the code from the data entry form page as well?
cgacfox posted this at 14:01 — 20th May 2004.
She has: 15 posts
Joined: May 2004
I have finished the data entry form and it works. One of the major problems that I was having was that I had set the table fields to not allow zero length. I corrected this because not all fields will be filled in for each movie. Also at another forum someone suggested this for my values:
VALUES(
'#Form.MovieTitle#',
'#Form.director#',
'#Form.mainActors#',
'#Form.studioHouse#',
'#Form.genre#',
'#Form.description#',
#Form.runningMinutes#,
'#Form.parentalRating#',
#Val(seriesFlag)#,
'#Form.seriesName#',
#Val(copyFlag)#,
#Val(mdlFlag)#,
#Val(gclFlag)#,
#Val(onloanFlag)#,
#CreateODBCDate(Form.onLoanDate)#NULL,
'#Form.onLoanName#',
'#Form.requestorName#'
)
This really worked well. I want to thank the people that helped me with this part of my project. I am now moving on to building an update form for the DVDs.
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.