Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Posting RadioButton Results to Database

Status
Not open for further replies.

mindeye

Technical User
Mar 12, 2002
40
US
Hello,

I have a form page and an action page. On the Form page my
buttons look like this:
<p> <cfinput type="radio" name="ListingType" checked="Yes" value="StandList">
</p>
<p><cfinput type="radio" name="ListingType" value="BoldList"></p>

I want to pass the value to the action page which in turn will pass it to a database. Should I have one field in my database called ListingType which will post the text (StandList or BoldList) or should I have two Fields one called StandList the other BoldList and have it set up with a Yes/No checkbox? I am not sure how to set up my database or how to set up my action page to post to it??

I am really stuck,
Roger
 
A radio button supports my assumption that you want the list one way or the other: Standard or Bold. A simple bit field called Bold would take care of it: False, standard list; True, bold list.

If you can have it both ways, you couldn't take of the data with one radio button set. You'd need checkboxes.

Phil Hegedusich
Senior Programmer/Analyst
IIMAK
-----------
I'm not as think as you confused I am.
-----------
Flabbergasted (a.): Amazed at how much weight one has gained.
-----------
Oyster (n.): One who sprinkles their conversation with Yiddish expressions.
 
But what if later down the road there's another option? Standard Listing, Bold Listing, and Color Listing. Now he has to go in and modify the table structure in order to make it work.

I would suggest having one field which will post the text of the radio button value. That way, if there are any changes later on, all you have to do is add another radio button and you're finished. No changes to the database.

Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
I was interested in posting text from the radio button. I wasn't exactly sure how the action page should be written to do this. The name is the container...in this case form.ListingType ... is that carrying the result...BoldList, StandList or ColorList? It doesn't seem to want to work if I create a field in the database called listing type. In other words it doesn't submit text (BoldList, StandList or ColorList). I have also tried creating to fields in the database called BoldList and StandList to see if it would post "Yes" for the selected result. I also read something about creating a cfloop ... I don't know how this works...

Thanks for getting me a little closer..

Regards,
Roger
 
Try this, if you have the following code in your form:
Code:
<p><cfinput type="radio" name="ListingType" value="StandList"></p>
<p><cfinput type="radio" name="ListingType"  value="BoldList"></p>
Then on your action page you should be able to do this and see what button was checked.
Code:
<cfoutput>#Form.ListingType#</cfoutput>
So, in your insert query you should be able to insert the value #Form.ListingType# into the ListingType field in the table.
Code:
INSERT INTO YourTableName(ListingType)
VALUES ('#Form.ListingType#')
Once you get that working, you should look at using cfqueryparam in your query, I just left it out in the example for the sake of simplicity.



Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
I tried that...this is the error I get(see below)...Here are my files... I have a field called ListingType in Microsoft Access. I am a graphics person trying to get into ColdFusion...I think I suck at this...

Thank you for your trouble...

Roger

The error occurred in C:\CFusionMX7\ line 22

20 : '#Trim(Form.ZipCode)#',
21 : '#Trim(Form.ListingType)#',
22 : <cfif Len(Trim(Form.Comments)) GT 0>'#Trim(Form.Comments)#'<cfelse>NULL</cfif>
23 : )
24 : </cfquery>



--------------------------------------------------------------------------------

SQL StandList INSERT INTO Company( CompanyName, Address, City, State, ZipCode, ListingType, Comments ) VALUES ( 'v', '41 Oatly Circle', 'Charleston', 'SC', '29414', 'StandList', 'cv' )
DATASOURCE CFMXBibleAccess
VENDORERRORCODE -3500
SQLSTATE 42000
 
What does the actual error message say? Is it a syntax error? If the datatype for ZipCode is numeric, remove the single quotes from around #Trim(Form.ZipCode)#.



Hope This Helps!

ECAR
ECAR Technologies

"My work is a game, a very serious game." - M.C. Escher
 
You will see the error below...I have pasted it from the page that was generated...

Thanks,
Roger


The web site you are accessing has experienced an unexpected error.
Please contact the website administrator.

The following information is meant for the website developer for debugging purposes.

Error Occurred While Processing Request
Error Executing Database Query.
[Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected 'DELETE', 'INSERT', 'PROCEDURE', 'SELECT', or 'UPDATE'.

The error occurred in C:\CFusionMX7\ line 22

20 : '#Trim(Form.ZipCode)#',
21 : '#Trim(Form.ListingType)#',
22 : <cfif Len(Trim(Form.Comments)) GT 0>'#Trim(Form.Comments)#'<cfelse>NULL</cfif>
23 : )
24 : </cfquery>



--------------------------------------------------------------------------------

SQL StandList INSERT INTO Company( CompanyName, Address, City, State, ZipCode, ListingType, Comments ) VALUES ( 'dgsd', 'd', 'dg', 'dg', '29414', 'StandList', 'sf' )
DATASOURCE CFMXBibleAccess
VENDORERRORCODE -3500
SQLSTATE 42000

Resources:
Check the ColdFusion documentation to verify that you are using the correct syntax.
Search the Knowledge Base to find a solution to your problem.


Browser Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.40607)
Remote Address 127.0.0.1
Referrer Date/Time 13-Dec-05 12:40 PM

Stack Trace (click to expand)
at cfCompanyAddAction2ecfm957096046.runPage(C:\CFusionMX7\ at cfCompanyAddAction2ecfm957096046.runPage(C:\CFusionMX7\

java.sql.SQLException: [Macromedia][SequeLink JDBC Driver][ODBC Socket][Microsoft][ODBC Microsoft Access Driver] Invalid SQL statement; expected &apos;DELETE&apos;, &apos;INSERT&apos;, &apos;PROCEDURE&apos;, &apos;SELECT&apos;, or &apos;UPDATE&apos;.
at macromedia.sequelink.ssp.Diagnostic.toSQLException(Unknown Source)
at macromedia.sequelink.ssp.Chain.cnvDiagnostics(Unknown Source)
at macromedia.sequelink.ssp.Chain.decodeDiagnostic(Unknown Source)
at macromedia.sequelink.ssp.Chain.decodeBody(Unknown Source)
at macromedia.sequelink.ssp.Chain.decode(Unknown Source)
at macromedia.sequelink.ssp.Chain.send(Unknown Source)
at macromedia.sequelink.ctxt.stmt.StatementContext.execDirect(Unknown Source)
at macromedia.jdbc.sequelink.SequeLinkImplStatement.execute(Unknown Source)
at macromedia.jdbc.slbase.BaseStatement.commonExecute(Unknown Source)
at macromedia.jdbc.slbase.BaseStatement.executeInternal(Unknown Source)
at macromedia.jdbc.slbase.BaseStatement.execute(Unknown Source)
at coldfusion.server.j2ee.sql.JRunStatement.execute(JRunStatement.java:212)
at coldfusion.sql.Executive.executeQuery(Executive.java:719)
at coldfusion.sql.Executive.executeQuery(Executive.java:652)
at coldfusion.sql.Executive.executeQuery(Executive.java:613)
at coldfusion.sql.SqlImpl.execute(SqlImpl.java:236)
at coldfusion.tagext.sql.QueryTag.doEndTag(QueryTag.java:499)
at cfCompanyAddAction2ecfm957096046.runPage(C:\CFusionMX7\ at coldfusion.runtime.CfJspPage.invoke(CfJspPage.java:152)
at coldfusion.tagext.lang.IncludeTag.doStartTag(IncludeTag.java:349)
at coldfusion.filter.CfincludeFilter.invoke(CfincludeFilter.java:65)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:210)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:51)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:86)
at coldfusion.filter.LicenseFilter.invoke(LicenseFilter.java:27)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:69)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.RequestThrottleFilter.invoke(RequestThrottleFilter.java:115)
at coldfusion.CfmServlet.service(CfmServlet.java:107)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:78)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:91)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:257)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:541)
at jrun.servlet.http.WebService.invokeRunnable(WebService.java:172)
at jrunx.scheduler.ThreadPool$DownstreamMetrics.invokeRunnable(ThreadPool.java:318)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:426)
at jrunx.scheduler.ThreadPool$UpstreamMetrics.invokeRunnable(ThreadPool.java:264)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top