I'm trying to insert rows from staffonblock table into the same staffonblock table.
The new rows will have the same groupid and staffid as the selected rows but the newblockid and newblocksetid will be as provided by the variables.
I'm calling the php file from a jQuery script using ajax and sending in the 4 variables but the ajax call returns an error, PHPMyadmin says the syntax of the php file is ok.
Here is staffonblock table before the required insert:
g1, s1, 1, 1
g1, s2, 1, 1
.. and eg what is required after insert:
g1, s1, 1, 1
g1, s2, 1, 1
g1, s1, 2, 2
g1, s2, 2, 2
help appreciated.
<?php
include_once ('tl2_connect.php'); $instance = ConnectDb::getInstance(); $conn = $instance->getConnection();
$groupid = $_POST["groupid"];
$blockid = $_POST["blockid"];
$newblockid = $_POST["newblockid"];
$newblocksetid = $_POST["newblocksetid"];
$sql = "INSERT INTO staffonblock (groupid, staffid, blockid, blocksetid)
SELECT groupid, staffid, ".$newblockid."', '".$newblocksetid."' FROM staffonblock
WHERE blockid='".$blockid."' AND groupid='".$groupid."';" ;
$conn->exec($sql)
?>