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

Insert from array form field.

Status
Not open for further replies.

joelxez

Programmer
Apr 18, 2002
67
PH
hi experts,

i have form with array fields. How do i set my query to insert value to table?

<form method="post" action="insert.cfm">
<input type="Text" name="t" value="a">
<input type="Text" name="t" value="b">
<input type="Text" name="t" value="b">
<input type="Submit" name="submit" value="OK">
</form>

Joel
 
this isn't php it's coldfusion. field values with multiple names are returned as a list not an array.
And even if it was PHP why are you using an array to insert TEXT? That's usualy used for checkboxes.

when dealing with most form fields use unique names like this.
Code:
<form method="post" action="insert.cfm">
    <input type="Text" name="textbox1" value="a">
    <input type="Text" name="textbox2" value="b">
    <input type="Text" name="textbox3" value="b">
    <input type="Submit" name="submit" value="OK">
</form>
When you insert it into your DB do it like this
Code:
<cfquery datasource = "#dsn#">
INSERT INTO table
             (field1, field2, field3)
      VALUES (
              <cfif isdefined("form.textArea1") and len(trim(form.textArea1))>
               '#form.textArea1#'
              <cfelse>
                 NULL
              </cfif>,
              [b]repeat for each field[/b]
</cfquery>

You can do it with a list like you do an array in PHP but I wouldn't recomend it.

Human beings, who are almost unique in having the ability to learn from the experience of others, are also remarkable for their apparent disinclination to do so.
-Douglas Adams (1952-2001)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top