Discussion:
<method="post"...>
(too old to reply)
blue skeleton
2009-03-02 04:45:29 UTC
Permalink
does ANYONE have a simple explanation on how to SIMPLY post form data to a
remote mysql database via CF8. Just looking for the basic syntax so i can
collect (one column table) email addresses from site visitors..

thanks a million !!!
Dan Bracuk
2009-03-02 14:02:23 UTC
Permalink
You don't post data to databases. You post data to cold fusion pages that
query databases. The tag you want to use is <cfquery>. Usage is described in
the cfml reference manual. If you don't have one, the internet does.
blue skeleton
2009-03-02 17:37:02 UTC
Permalink
Thanks for the quick reply and directon Dan! As you probably guessed, i am a
few days into CF8, a 'newbie' if you will.... I was able to get a reference
guide this morning from the bookstore and put together the following:

Can someone let me know if this is correct and why my MySQL database is not
being updated with the data. I have datasource and table setup correctly..
Please explain any steps, this is the first CF8 I have ever written... :)

thanks !!!! :confused;

<CFQUERY NAME="insertFormData" DATASOURCE="blueskeleton">
INSERT INTO emails (emailAddress)
VALUES (#form.formData#')
</CFQUERY>

email added. Thanks


<!--- here is my actual form --->

<cfform method="post" name"Email Address" preloader="no" lang="en" dir="ltr">
<center>
<strong>Monthly Newsletter</strong><br />
<em><small>enter your email address here</small></em><br />
<cfinput type="text" name="" validateat="onSubmit" validate="email"
required="yes" maxlength="45" typeahead="no" showautosuggestloadingicon="true'>
<br />
<cfinput type="submit" name="Submit" id'="Submit" value="Submit">
</center>
</cfform>

<!--- end of form --->
Azadi
2009-03-03 06:00:00 UTC
Permalink
your code:
<cfinput type="text" name="" validateat="onSubmit" validate="email"
required="yes" maxlength="45" typeahead="no"
showautosuggestloadingicon="true'>

you should give your field a proper NAME, and then reference that name
in your INSERT query. CF uses the NAME attribute to get filed values -
so always provide a valid** NAME to your form controls (**valid =
conforms to CF variable naming rules).

<cfif structkeyexists(form, 'submit') AND len(trim(form.email_address))>
<!--- form has been submitted and email_address field is not empty:
insert into db --->
<CFQUERY NAME="insertFormData" DATASOURCE="blueskeleton">
INSERT INTO emails (emailAddress)
VALUES ('#form.email_address#')
</CFQUERY>
<!--- do whatever you need to do now that the email has been inserted
into db --->
</cfif>

...
<cfinput type="text" name="email_address" validateat="onSubmit"
validate="email" required="yes" maxlength="45">
...

also, your query was missing an opening ' in front of the inserted value...
also, in your <cfform> tag you seem to be missing = in the NAME attribute...
also, you have a stray ' after ID in your submit button code...

Azadi Saryev
Sabai-dee.com
http://www.sabai-dee.com/

Dan Bracuk
2009-03-02 18:57:35 UTC
Permalink
Your code looks ok. What indication do you have that the record is not being inserted?
Loading...