Good day! Help plz. sort out. It is necessary to make a copy of the goods within the same sql table. For example, there is a table of goods from the intern store and there are similar products that are too lazy to re-enter every time, but it would be convenient to click on a similar product "Copy", correct the necessary data and add as a new product.

I wanted to do it on the basis of the delete function, replacing $ action with $ action_copy and "delete" with "copy", but failed

$action = $_GET["action"]; if (isset($action)) { $id = (int)$_GET["id"]; switch ($action) { case 'delete': if ($_SESSION['delete_tovar'] == '1') { $delete = mysql_query("DELETE FROM category WHERE id = '$id'",$link); }else { $msgerror = 'Π£ вас Π½Π΅Ρ‚ ΠΏΡ€Π°Π² Π½Π° ΡƒΠ΄Π°Π»Π΅Π½ΠΈΠ΅ Ρ‚ΠΎΠ²Π°Ρ€ΠΎΠ²!'; } break; } } 

    1 answer 1

     mysql_query("INSERT INTO category SELECT * FROM category WHERE id = '$id'",$link); 

    But! If the ID field is a primary key or there is a unique index on it, then the ID field should be excluded from the insert. For this it is necessary to list all the fields of the table except the ID. Those.

     INSERT INTO category (<список ΠΏΠΎΠ»Π΅ΠΉ ΠΊΡ€ΠΎΠΌΠ΅ ID>) SELECT <список ΠΏΠΎΠ»Π΅ΠΉ ΠΊΡ€ΠΎΠΌΠ΅ ID> FROM category WHERE id = 

    Another option is to do the same - select the record with a select and insert it with a separate insert.

    • Thank! It really works !!!!!!!!!!! You really helped! - billov
    • @billov Mark the answer as true, if it really helped you - Tivyram