This topic is locked

Copy Data from one table to another table

10/21/2022 12:27:53 AM
PHPRunner General questions
S
Sayed author

$InvoiceID = $record['InvoiceID']; //Invoice Table, Add Page

$StudentID = $record['StudentID']; //Invoice Table Add Page

$PackageID = $record['PackageID']; //Invoice Table Add Page

//Getting Data from This Table, Services

$sql = "select * from Services where PackageID = ".$PackageID;

$rs = DB::Query($sql);

while ($data = $rs->fetchAssoc())

{

//Saving Data in this table, StudentServices

$sql2 = "INSERT INTO StudentServices (StudentID, PackageID, InvoiceID, ServiceType, Service, QTY, Details, School )

VALUES (" . $StudentID . "," . $PackageID . "," . $InvoiceID . ", '" . $data['ServiceType'] . "', '" . $data['Service'] . "', " . $data['QTY'] . ", '" . $data['Details'] . "', '" . $data['School'] . "')";

DB::Exec($sql2);

}

Above code does not insert any data. and its giving error.
Fatal error: Call to a member function fetchAssoc() on boolean in...
Please guide what wrong. Thanks

mbintex 10/21/2022

Insert into based on a select would be much easier in my eyes

https://www.w3schools.com/mysql/mysql_insert_into_select.asp