PDO Insert multiple checkbox values in Mysql

tslopes

I want insert multiple checkbox values in Mysql using PDO.

HTML Form part checkbox

<form action="insert.php">
    <label>
        <input name="check[]" id="check[]" type="checkbox" value="<?=$row['id']?>" />
        <span class="lbl"></span>
    </label>
    <button type="submit" name="send" id="send" >
</form>

PHP Part insert

$checkbox = $_POST['check'];

for (i$=0; $i<sizeof($checkbox);$i++)

    $insert = $pdo->prepare("INSERT INTO table (check_value) VALUES (?)");
    $insert->execute(array(".$checkbox[$i]."));

More when i use ".$checkbox[$i]." give "Notice: Array to string conversion"

DarkBee

One way to do this is build the SQL dynamicaly. Just add as many ? to the SQL as there are checkbox values.

<?php
if (isset($_POST['check'])) {
    $sql = 'INSERT INTO TABLE (check_value) VALUES ({foo})';

    $foo = '';
    foreach($_POST['check'] as $key => $value) $foo .= '?,';
    $foo = rtrim($foo, ',');

    $sql = str_replace('{foo}', $foo, $sql);

    $insert = $pdo->prepare($sql);
    $insert->execute($_POST['check']);
}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How do I insert multiple checkbox values into a table?

From Dev

MySQL - INSERT multiple values conditionally

From Dev

Converting MySql Insert To PDO

From Dev

PDO insert not inserting with multiple values

From Dev

get first insert id for multiple insert using pdo in mysql

From Dev

What is the best way to insert multiple rows in PHP PDO MYSQL?

From Dev

PHP PDO Multiple image INSERT

From Dev

how to insert multiple of values in a single field in mysql

From Dev

MySQL query for multiple checkbox values

From Dev

Insert multiple values in one column of mysql database

From Dev

Joining array values into string in MySQL multiple insert

From Dev

MYSQL - PDO with multiple IN clause

From Dev

INSERT INTO array with MySQL and PDO

From Dev

Insert multiple values via PHP PDO into MySQL database

From Dev

MYSQL Insert Where Not Exists with PDO

From Dev

MySQL - INSERT multiple values conditionally

From Dev

Insert post with multiple tags in PDO

From Dev

Multiple values into MySQL from checkbox

From Dev

Multiple checkbox database insert with mysql prepare

From Dev

Insert values from multiple arrays into MySQL

From Dev

Pdo multiple row insert issue

From Dev

Joining array values into string in MySQL multiple insert

From Dev

how to insert multiple checkbox values in single column in database using php

From Dev

how to make an insert function with in a database class to insert a new record with multiple coloumns and multiple values (using PDO )?

From Dev

PHP, PDO, MySQL - Multiple INSERT vulnerable to injection?

From Dev

PDO / mySQL How to bind multiple values to store multiple rows

From Dev

Insert multiple values from API into mysql database

From Dev

PDO insert BindParam mysql

From Dev

how to Insert multiple arrays with multiple rows into MySQL using PHP PDO

Related Related

  1. 1

    How do I insert multiple checkbox values into a table?

  2. 2

    MySQL - INSERT multiple values conditionally

  3. 3

    Converting MySql Insert To PDO

  4. 4

    PDO insert not inserting with multiple values

  5. 5

    get first insert id for multiple insert using pdo in mysql

  6. 6

    What is the best way to insert multiple rows in PHP PDO MYSQL?

  7. 7

    PHP PDO Multiple image INSERT

  8. 8

    how to insert multiple of values in a single field in mysql

  9. 9

    MySQL query for multiple checkbox values

  10. 10

    Insert multiple values in one column of mysql database

  11. 11

    Joining array values into string in MySQL multiple insert

  12. 12

    MYSQL - PDO with multiple IN clause

  13. 13

    INSERT INTO array with MySQL and PDO

  14. 14

    Insert multiple values via PHP PDO into MySQL database

  15. 15

    MYSQL Insert Where Not Exists with PDO

  16. 16

    MySQL - INSERT multiple values conditionally

  17. 17

    Insert post with multiple tags in PDO

  18. 18

    Multiple values into MySQL from checkbox

  19. 19

    Multiple checkbox database insert with mysql prepare

  20. 20

    Insert values from multiple arrays into MySQL

  21. 21

    Pdo multiple row insert issue

  22. 22

    Joining array values into string in MySQL multiple insert

  23. 23

    how to insert multiple checkbox values in single column in database using php

  24. 24

    how to make an insert function with in a database class to insert a new record with multiple coloumns and multiple values (using PDO )?

  25. 25

    PHP, PDO, MySQL - Multiple INSERT vulnerable to injection?

  26. 26

    PDO / mySQL How to bind multiple values to store multiple rows

  27. 27

    Insert multiple values from API into mysql database

  28. 28

    PDO insert BindParam mysql

  29. 29

    how to Insert multiple arrays with multiple rows into MySQL using PHP PDO

HotTag

Archive