mass insert using textfield? MySQL

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default mass insert using textfield? MySQL

    Is it possible to insert multiple records at once using a textfield? One of the problems I see first off is the use of tabs in a webform. Any
    thoughts? Is there a more efficient way?

    stillwaiting
    stillwaiting Guest

  2. Similar Questions and Discussions

    1. CFMX & MySQL : getting the id of the last insert
      <cftransaction> <cfquery> Insert Into myTable(col1, col2) Values('value1', 'value2') </cfquery> <cfquery> Select MAX(ID) As LastInserted From...
    2. id after insert in MySQL
      I'm trying to obtain the id of an INSERTed MySQL record (which is set as AUTO INCREMENT in my table btw). I believe the php function is...
    3. Textfield.html = true vs TextField.setTextFormat
      H I need to use html textfield to control when the text must change the line (br tag). The problem is that I can't use setTextFormat if I use html...
    4. mass migration from mysql?
      considering the recent changes to the mysql licensing terms, which meant the php5 team had to adopt sqlite instead into the php5 and drop mysql...
    5. Forgot how to do a mass update in mySQL
      I can't remember if I did this last time in phpMyAdmin or if I did it some other way... I have 2 new fields in a database that I need to fill with...
  3. #2

    Default Re: mass insert using textfield? MySQL

    Do you mean, "enter a list of values into this field" and each value is a new
    record in the db? It's possible, just depends on how you do it. You can have
    people enter a list of things, seperated by a comma, semi-colon, etc into an
    <input type="text"> field. Or you can have people enter data into a <textarea>,
    puting each item on a new line.

    Either way, you just have to read the value of the field in and parse it as a
    list using the delimeter you set. In the case of the <textarea>, the delimeter
    would be the newline character.

    HTH

    cf_menace Guest

  4. #3

    Default Re: mass insert using textfield? MySQL

    Okay, that is the general idea but how do I tell MySQL that the comma(or whatever) separates the data and what is the SQL that is used in the insert
    statement?
    I looked through the MySQL manual and they only tell how to specify the delimiter when doing LOAD DATA LOCAL INFILE.

    I have a table with 4 fields, the first being an auto number that doesn't get a value from the form. I want the user to be able to write the
    information in the text box like this:

    link1, link1b, link1description
    link2, link2b, link2description
    link3, link3b, link3description

    each line needs to be a new record with the commas specifying a new column.

    I guess I just need a little more to go on. Must be short on brain cells.

    stillwaiting

    p.s. Thanks for the help so far.
    > Do you mean, "enter a list of values into this field" and each value is a new
    > record in the db? It's possible, just depends on how you do it. You can have
    > people enter a list of things, seperated by a comma, semi-colon, etc into an
    > <input type="text"> field. Or you can have people enter data into a <textarea>,
    > puting each item on a new line.
    >
    > Either way, you just have to read the value of the field in and parse it as a
    > list using the delimeter you set. In the case of the <textarea>, the delimeter
    > would be the newline character.
    >
    > HTH
    >
    stillwaiting Guest

  5. #4

    Default Re: mass insert using textfield? MySQL

    >how do I tell MySQL that the comma(or whatever) separates the data and
    >what is the SQL that is used in the insert statement?
    As cf_menace mentioned, you will need to read data in the form variable
    yourself. Then split the variable data into rows and columns and construct
    your sql statements. Here is a simple example using a text area, it needs
    validation etc, but you should get the idea...







    <!--- form code --->
    <form method="post">
    <textarea name="userData" cols="80" rows="25">
    link1, link1b, link1description
    link2, link2b, link2description
    link3, link3b, link3description
    </textarea>
    <input type="submit">
    </form>


    <!--- action page code --->
    <cfset colDelim = ",">
    <cfset rowDelim = chr(10)>
    <cfloop list="#form.userData#" index="row" delimiters="#rowDelim#">
    <cfset columns = listToArray(row, colDelim)>
    <cfif arrayLen(columns) eq 3>
    <cfset linkAddress = trim(columns[1])>
    <cfset linkTitle = trim(columns[2])>
    <cfset linkDescription = trim(columns[3])>
    <cfquery name="insertData" datasource="#yourDSN#">
    INSERT INTO yourTable (address, title, description)
    VALUES
    (
    <cfqueryparam value="#linkAddress#" cfSqlType="cf_sql_varchar">,
    <cfqueryparam value="#linkTitle#" cfSqlType="cf_sql_varchar">,
    <cfqueryparam value="#linkDescription#" cfSqlType="cf_sql_varchar" >
    )
    </cfquery>
    </cfif>
    </cfloop>

    mxstu Guest

  6. #5

    Default Re: mass insert using textfield? MySQL

    Thanks mxstu. That was really helpful.

    stillwaiting

    mxstu wrote:
    >>how do I tell MySQL that the comma(or whatever) separates the data and
    >
    > >what is the SQL that is used in the insert statement?
    >
    > As cf_menace mentioned, you will need to read data in the form variable
    > yourself. Then split the variable data into rows and columns and construct
    > your sql statements. Here is a simple example using a text area, it needs
    > validation etc, but you should get the idea...
    >
    >
    >
    >
    >
    >
    >
    > <!--- form code --->
    > <form method="post">
    > <textarea name="userData" cols="80" rows="25">
    > link1, link1b, link1description
    > link2, link2b, link2description
    > link3, link3b, link3description
    > </textarea>
    > <input type="submit">
    > </form>
    >
    >
    > <!--- action page code --->
    > <cfset colDelim = ",">
    > <cfset rowDelim = chr(10)>
    > <cfloop list="#form.userData#" index="row" delimiters="#rowDelim#">
    > <cfset columns = listToArray(row, colDelim)>
    > <cfif arrayLen(columns) eq 3>
    > <cfset linkAddress = trim(columns[1])>
    > <cfset linkTitle = trim(columns[2])>
    > <cfset linkDescription = trim(columns[3])>
    > <cfquery name="insertData" datasource="#yourDSN#">
    > INSERT INTO yourTable (address, title, description)
    > VALUES
    > (
    > <cfqueryparam value="#linkAddress#" cfSqlType="cf_sql_varchar">,
    > <cfqueryparam value="#linkTitle#" cfSqlType="cf_sql_varchar">,
    > <cfqueryparam value="#linkDescription#" cfSqlType="cf_sql_varchar" >
    > )
    > </cfquery>
    > </cfif>
    > </cfloop>
    >
    stillwaiting Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139