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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Coldfusion radio button into to database

Status
Not open for further replies.

3443232

Technical User
Dec 18, 2003
6
US
I am working in creating a form and add the information to my SQL database. for a text input a use <CFINSERT DATASOURCE=&quot;datasoursename&quot; TABLENAME=&quot;tablename&quot; FORMFIELDS=&quot;formfield1,formfield2,&quot;>
I have a male and female radio button option and I would like to add it in my database if the visitor is male or female but I do not know how.
I also have an upload button where visitor upload files. I know how to safe this file in a folder but I do not know how to record the path of the file into my database at the same time that is been uploaded.
Can someone help me?

Thanks
hcanizares@yahoo.com
 
Hello,

I looked at your page and one thing I noticed is that your radio butons: &quot;masculino&quot; and &quot;femenino&quot; don't exclude each other. So a person could select both. If you name them the same then you can only have one selected... which is probably what you're after.

so if you change it to:
Code:
<label>
<input name=&quot;sexo&quot; type=&quot;radio&quot; value=&quot;masculino&quot; checked> masculino</label>
<label><input name=&quot;sexo&quot; type=&quot;radio&quot; value=&quot;femenino&quot;> femenino</label>
then from your CFM you can do this:
Code:
<cfif isDefined(&quot;form.sexo&quot;)>
  <cfset sexo = #form.sexo#>
<cfelse>
  <!---   Go back and select Sexo --->
  <!---   Not actually possible seeing as you auto-select
          masculino but good practice --->
          
</cfif>
then insert the variable sexo into the database.
That is of course assuming that you have a varchar (text) field setup in the database for &quot;Sexo&quot;

let me know if it works for you. If not, give me some more info about the database field that you are using to hold the sex and I'll try to adjust it for you.




Travis Hawkins
BeachBum Software
travis@cfm2asp.com
 
SO this is what i understand
<cfif isDefined(&quot;form.sexo&quot;)>
<cfset sexo = #form.sexo#>
<cfelse>
WHAT DO I WRITE HERE?
</cfif>

I BELIVE THAT NEXT IS MY INSERT TO DATABASE IF THE VISITOR IS FEMENINO OR MASCULINO

<CFINSERT DATASOURCE=&quot;datasoursename&quot; TABLENAME=&quot;tablename&quot; FORMFIELDS=&quot;SEXO&quot;>
My table in database is called &quot;estudiante&quot; and the field is &quot;sexo&quot;
 
Don't use <cfinsert> or <cfupdate> (ever), write you're own SQL Statements using <cfquery>. <cfinsert> and <cfupdate> are unstable, and have been know to break and cause problems for no reason.
Try:

<cfif isDefined(&quot;form.sexo&quot;)>
<cfset sexo = #form.sexo#>
<cfelse>
<cfset sexo = &quot;Unknown&quot;>
<!--- OR, here you could throw an error or force the user to go back and select a value or whatever else you want to happen. --->
</cfif>

<CFQUERY NAME=&quot;insert_SEXO&quot; DATASOURCE=&quot;datasoursename&quot;>
INSERT INTO estudiante(sexo)
VALUES(#sexo#)
</CFQUERY>


Hope This Helps!

Ecobb

&quot;Alright Brain, you don't like me, and I don't like you. But lets just do this, and I can get back to killing you with beer.&quot; - Homer Simpson
 
Great, works perfect! Now I have two more problems.

I have a drop down &quot;Nombre del Manual/curso&quot; with many options that I pulled from the database. I would when they choose one of the options the option got recorded in the database.

The other problem is in the upload file input “Subir Manual” where visitor can upload file and get saved into a folder. I used <CFFILE> so the file get save into a folder that specified but I do not know how make the path of the file uploaded into the database as path link to the file.

Thanks so much
Henry
 
For your select box you can use something like this in a form tag:


<select name=&quot;selectname&quot;>
<cfoutput query=&quot;yourquery&quot;>
<option value=&quot;#yourquery.info>&quot;#yourquery.info#&quot;</option>
</cfoutput>
</select>

And on your action page here is how it would be submitted:
<cfif IsDefined(&quot;FORM.selectname&quot;) AND #FORM.selectname# NEQ &quot;&quot;>
'#FORM.selectname#'
<cfelse>
NULL
</cfif>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top