I can not understand what is missing in the code, I need to copy a few lines from the table based on the selected checkbox , I have a checkbox array called abs to process the data. Here is the php copy code. I will explain the condition, if the copypast button is pressed and the checkbox selected in the abs array, the condition is met, the rows in the table are copied, I cannot connect the abs checkbox to the abs checkbox array

  if (isset($_POST['copypast']) and(!empty($_POST['abs']))) { $id = $_POST['id']; $result = $dbh - > query("SELECT * FROM tovars WHERE id=$id") - > fetch(); $result['flag'] = 0; $result['id'] = 0; foreach($result as $k = > $v) { $fields[] = $k; $vals[] = "'$v'"; } $fields1 = implode(", ", $fields); $vals1 = implode(", ", $vals); $q = "INSERT INTO tovars (".$fields1. ") VALUES (".$vals1. ")"; $query = $dbh - > prepare($q); $query - > execute(); } else { echo "не работает"; } 

the form with the table is http://jsfiddle.net/gxpfo5j8/

I didn’t add, when copying several lines these lines should be inserted into the table, the above code only works if for example there is a button on each line and when I click on it one line will be copied, but I need to copy several lines. Tell me how you can implement

    2 answers 2

    Wrap the entire table in a form:

     <form> <table> <tr> <th>тескт</th> <th><input type= checkbox name = "abs<?php echo $id ?>" ></th> </tr> <tr> <th>тескт</th> <th><input type= checkbox name = "abs<?php echo $id ?>" ></th> </tr> </table> </form> 

    Further on php in a cycle You pull out ID and check with "abs<?php echo $id ?>"

    • If you didn’t know: here you can edit the text of the question, do not write in the comments what you didn’t add - HELO WORD
    • I have not been here at all for a long time, so I didn’t know how to do it) - Eliot
    • "edit" button in question - HELO WORD
    • Found, thanks) - Eliot

    Solved the problem, wrote one query, example: INSERT INTO (pole1, pole2) SELECT (pole1, pole2) for copying rows in the table and it all worked.