How to save several input data in single MySql column?

how to insert multiple values in one column in sql
how to insert multiple values in a single column in mysql using php
how to get multiple values in single column in mysql
how to insert data into multiple tables using single query in mysql
insert multiple rows into mysql with php using foreach arrays
multiple inserts in one statement mysql
how to insert multiple rows in mysql in one query using php
mysql insert multiple rows

How to save several input data in single MySql column?

I have 3 input fields, with same name (name="type"). Now I want to save these 3 input fields datas in one, single Mysql column. How can I solve this?

  <div class="form-column col-md-4">
      <div class="form-group col-md-12">
         <input type="text" class="form-control" name="type"  id="height" placeholder="height (cm)">
      </div>
      <div class="form-group col-md-12">
         <input type="text" class="form-control" name="type" id="width" placeholder="width (cm)">
      </div>
      <div class="form-group col-md-12">
         <input type="text" class="form-control" name="type" id="length" placeholder="length (cm)">
      </div>
   </div>

HTML

<form >
 <div class="form-column col-md-4">
  <div class="form-group col-md-12">
     <input type="text" class="form-control" name="type[width]"  id="height" placeholder="height (cm)">
  </div>
  <div class="form-group col-md-12">
     <input type="text" class="form-control" name="type[height]" id="width" placeholder="width (cm)">
  </div>
  <div class="form-group col-md-12">
     <input type="text" class="form-control" name="type[length]" id="length" placeholder="length (cm)">
  </div>

Note when naming the variable in html use specifically name="type[width]". do not use the single or double quote inside with width like names

PHP

<pre>
 <?php  


     $type = $_GET['type'];
     print_r($type);
     extract($type);

        echo 'width:' . $width .'<br />';
        echo 'height:' . $height .'<br />';
        echo 'length:' . $length .'<br />';


   //serialize before inserting
   $mysql_value = serialize($type);
   echo $mysql_value;

   //retrive by unserialize
   $unserialize_mysql_value = unserialize($mysql_value);
   print_r($unserialize_mysql_value);


    ?></pre>

Documentation of extract function

MySQL Insert Multiple Rows By Practical Examples, MySQL Insert Multiple Rows. First, specify the name of table that you want to insert after the INSERT INTO keywords. Second, specify a comma-separated column list inside parentheses after the table name. Third, specify a comma-separated list of row data in the VALUES clause. Each element of the list represents a row. Notice that the query simply retrieves the owner column from each record, and some of them appear more than once. To minimize the output, retrieve each unique output record just once by adding the keyword DISTINCT :

I don't recommend it, but you could create an assoc array with the names and values and save it as a JSON string in the database using json_encode(). Then you can use json_decode() to get the array again and have access each field individually.

Multiple Inserts for a single column in MySQL?, The syntax for multiple inserts for a single column in MySQL is as follows −​INSERT INTO yourTableName(yourColumnName)  The MySQL server normally returns the result of a SELECT statement to the client that issued the statement. For example, when you issue a statement from within the mysql program, the server returns the result to mysql, which in turn displays it to you on the screen.

Change the name from name="type" to name="type[]" and the data will POST as an array.

When handling the request body, you can concatenate these however you'd like to be stored.

ex: $column_val = $request->type[0] . $request->type[1];

or: $column_val = implode('-', $request->type);

How to insert multiple values in a specific field in a table using mysqli?, No. Don't put multiple values in a column; make a new table: Mapping table -id -- same as the `id` in transaction_tbl -ref_number PRIMARY KEY(id, ref_number). A source column may be mapped to multiple target columns, although this action generates a warning dialog. Right-clicking a target column shows a context menu with options to either Remove Column Mapping for a single column, or to Clear All Mappings for all columns. Dragging a target column outside of the grid removes the mapping.

You can't use same name for multiple input, if you want to use same name then you can use name attribute like an array, something like:

name="type[]"

Now, you can use serialize() method in PHP to store all inputs in one single column something like:

$inputData = serialize($_POST['name']); // this will store your array as a string

After this, when you need to display this column then you can use unserialize() method like:

$fetchData = unserialize(your column name); 

Here, $fetchData will return the original array, which you saved in your database.

Additional Point:

You can also store your input with associative array like:

name="type[width]" and name="type[height]" and name="type[length]"

Insert multiple records into MySQL with a single query, It is possible to insert multiple records into MySQL using a comma separated list to use a different variable for each value or just a variable for each table column. It's not really any different from looping through data to create a single query,  mysql> LOAD DATA LOCAL INFILE '/path/pet.txt' INTO TABLE pet LINES TERMINATED BY '\r '; (On an Apple machine running macOS, you would likely want to use LINES TERMINATED BY '\r' .) You can specify the column value separator and end of line marker explicitly in the LOAD DATA statement if you wish, but the defaults are tab and linefeed.

PHP MySQL Insert Multiple Records, While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 1999-2020 by Refsnes Data. All Rights Reserved  How to Add Data in a MySQL table. The MySQL Insert process can be carried out in several ways: through a direct command from the command line of the MySQL console, via the web-based graphic interface PHPMyAdmin, and by using a PHP script (inserting data and scripts written in other languages - Perl, Python, etc., is possible as well). All MySQL

MySQL 8.0 Reference Manual :: 8.3.6 Multiple-Column , For certain data types, you can index a prefix of the column (see Section 8.3.5, a single composite index can speed up several kinds of queries on the same  I've a csv file which contains data with new lines for a single row i.e. one row data comes in two lines and I want to insert the new lines data into respective columns. I've loaded the data into sql but now I want to replace the second row data into 1st row with respective column values. ID Name Department DOB State Country Salary

MySQL Tutorial :: 4.3 Loading Data into a Table, The LOAD DATA and INSERT statements are useful for this. your animals, then load the contents of the file into the table with a single statement. given in the order in which the columns were listed in the CREATE TABLE statement. initially using several INSERT statements rather than a single LOAD DATA statement. If a result set contains columns in several character sets, so will the output data file and it may not be possible to reload the file correctly. The syntax for the export_options part of the statement consists of the same FIELDS and LINES clauses that are used with the LOAD DATA statement.

Comments
  • serialize() ???? or if u are asking input field then name="type[]
  • don't - it'll make running queries on any given dimension an absolute bum (<- polite version).
  • did u checked the solutions?
  • looks like copied the complete the suggestion from other answer :)
  • Your Welcome Bro. @devpro and yes please read the answer with open eyes and OPEN MIND