How to combine these both Query into Single Query
$sql = "INSERT INTO deletedtemplate (template) SELECT template FROM template WHERE id = $id";
$sql1 = "DELETE FROM template WHERE id = $id ";
Simply you can combine these both query using this:
$sql = "INSERT INTO deletedtemplate (template) SELECT template FROM template WHERE id = $id; DELETE FROM template WHERE id = $id ";
You can not have these 2 queries together, however the same could be handled via trigger something as
delimiter //
create trigger template_del before delete on template
for each row
begin
insert into deletedtemplate (template)
SELECT template FROM template WHERE id = old.id ;
end;//
delimiter ;
So if you delete something on template an insert will happen on the deletedtemplate table
Try this... and maybe make the name of your field different than the name of your table... so table would still be template, but change the field currentTemplate or something like that. I'm not sure if that might be causing any issues but it makes it less confusing to read/edit the query that's for sure.
REPLACE INTO
`deletedtemplate`
(`template`)
select
`template`
from
`template`
where
`id` = $id;