Hello,
I have a preloaded database that I would like for my users to be able check (via a form with checkboxes) the items they can use for their project, while copying those columns to a different table for future reference, and meanwhile deleting the columns from the first table so they are not displayed in the initial form the next time a user checks availability of the items.
The code I'm currently using will delete the columns from the first table, but will not copy them to the second table. Please let me know what I could try to correct the following code.
Thank in advance for any help you can give!
I have a preloaded database that I would like for my users to be able check (via a form with checkboxes) the items they can use for their project, while copying those columns to a different table for future reference, and meanwhile deleting the columns from the first table so they are not displayed in the initial form the next time a user checks availability of the items.
The code I'm currently using will delete the columns from the first table, but will not copy them to the second table. Please let me know what I could try to correct the following code.
Code:
$dbconn = mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
if($_POST['delete']) // from button name="delete"
{
$checkbox = $_POST['checkbox']; //from name="checkbox[]"
$countCheck = count($_POST['checkbox']);
for($i=0;$i<$countCheck;$i++)
{
$del_id = $checkbox[$i];
$sql = "INSERT INTO table2 (col1, col2, col3, col4) SELECT col1, col2, col3, col4 FROM table1 WHERE id='$del_id'";
$sql = "delete from table1 where id = $del_id";
$result = mysql_query($sql, $dbconn);
}