This topic is locked

Issues with DB::Exec and DB::Insert

4/3/2020 9:54:29 AM
PHPRunner Tips and Tricks
P
pwburton author

How to use a custom Button on a Source Table to insert 1 or more records to a target table using a custom button

(Issue Resolved with DB::Insert)
Custom Button Code Example

Source Table = demo.questions

Target Table = demo.responses

Source and Target Tables have the identical columns:

QuestionNo, Classification, QuestionText
=======Client Before=========================

params["var1"] = prompt("Please enter the Query Parameter ID", " ");
=========ServerCode==========================

$record = $button->getNextSelectedRecord();

$result["var2"] = $params["var1"]."Info Added to Table ".$record["ID"]."Q#: ".$data["QuestionNo"] ;

$data2 = array();

//

$rs = DB::Query("SELECT QuestionNo, Classification, QuestionText FROM demo.questions where ID ='".$params["var1"]."'");

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

{

$data2["SiteID"] = $record["ID"];

$data2["QuestionNo"] = $data["QuestionNo"];

$data2["Classification"] = $data["Classification"];

$data2["QuestionText"] = $data["QuestionText"];

DB::Insert("responses", $data2);

}
========= Client After===========================
//

// Nothing needed here

//