Pete666 Posted January 7, 2023 Share Posted January 7, 2023 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) ?> Quote Link to comment https://forums.phpfreaks.com/topic/315768-insert-into-select/ Share on other sites More sharing options...
Solution Barand Posted January 7, 2023 Solution Share Posted January 7, 2023 13 minutes ago, Pete666 said: WHERE blockid='".$blockid."' AND groupid='".$groupid."'; That will only select one record (g1/s1 or g1/s2) so you will only insert one new record Quote Link to comment https://forums.phpfreaks.com/topic/315768-insert-into-select/#findComment-1604391 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.