Skip to main content
Known Participant
March 24, 2014
Question

Selecting variable from form and posting to mysql

  • March 24, 2014
  • 1 reply
  • 1100 views

I have and exisiting form and I want to take the email and name from the form and input it into mysql database of emaillist . I also only want to do this if the i wish to subscribe is selected.

Quotation Request For:

Date: #DateFormat( Now(), "MMMM DD, YYYY")#
Need By: #form.needby#
Company: #form.company#
Name #form.firstname# #form.lastname#
Title: #form.title#
Address:
#form.address#
#form.city#, #form.state#, #form.zip#
phone: #form.phone#
fax: #form.fax#
e-mail: #form.email#
Reference: #form.reference#

Description

Truck Mounted Tank Capacity: #form.capacity#
Fill Valve: Size: #form.fill_valve_size# Style: #form.fill_valve_style#
Discharge Valve: Size: #form.discharge_valve_size#
Vacuum Pump:
#form.vacuum_pump# : #form.other_vacuum_pump#
Aluminum Toolbox, Size: #form.toolbox_size#
Mounting: #form.mounted#
Misc. Custom Features:
#form.custom_features#

Service Units

#form.port_toilet_service#

Units

Material: #form.scu_material#
Number of Compartments:#form.compartment#
Vacuum Pump:#form.scu_vacuum#
Size:#form.scu_size#

Additional Notes For This Request:

#form.notes#

Email Subscirption

#form.subscribe#

Your request has been forwarded to I.. Thank you for your interest, we will be in contact with you shortly.

CLOSE PAGE

This topic has been closed for replies.

1 reply

BKBK
Community Expert
Community Expert
March 26, 2014

You should count yourself lucky whenever a user is prepared to supply you such elaborate information. Data is money. You should save the data unconditionally. However, you should also record whether or not the user wants to subscribe.

The context underlying all of this is that you can identify each user. That in turn means you should implement login.

The standard way to process the form is by means of code like the following, in the action page of the form:

<cfif isDefined("form.lastname")>

    <cfquery name="saveUserDetails" datasource="myDSN">

        insert into userTable ... etc., etc.

    </cfquery>

    <cfquery name="saveToolDetails" datasource="myDSN">

        insert into componentPartsTable... etc., etc.

    </cfquery>

</cfif>

Guy DowdAuthor
Known Participant
March 26, 2014

I added below to my action page and receive this error

Element DSN is undefined in REQUEST

<cfset FullName = '#form.firstname# #Form.lastname#'>

<cfquery  name = "AddtoMailingList" Datasource = "#request.dsn#">

INSERT INTO emaillist

(CustomerName, CustomerEmail)

VALUES

('#FullName#', '#form.CustEmailAddress#')

</CFQUERY>          

Dave Ferguson
Participating Frequently
March 26, 2014

Unless you have defined the var request.dsn it will error.  I would look at other queries you have in your system and see what they have for the datasource attribute and use that.

Now, some pointers with your actuall code...

  • I wouldn't combine the names before insert.  It will be very difficult later to only use the first name (as an example) if you want to.
  • You should be using a query param for all input vars... see example below.

<cfquery  name = "AddtoMailingList" Datasource = "#request.dsn#">

INSERT INTO emaillist

(CustomerName, CustomerEmail)

VALUES

(

<cfqueryparam value="#FullName#" cfsqltype="cf_sql_varchar" >,

<cfqueryparam value="#form.CustEmailAddress#" cfsqltype="cf_sql_varchar">

)

</cfquery>

Hope this helps.

--Dave