I have a code testing table in my database called multi_add. It has 3 columns, MA_ID, Name, List. I’m trying to create a button that will allow me to select 1 or more records on a grid, copy all of their data and make new records using that data into the same table for editing later. I’ve successfully been able to copy the records in SQL and through your SQL builder with this code:
SQL:
INSERT INTO multi_add(Name, List)SELECT Name, List FROM multi_add
SQL Builder in Scriptcase:
INSERT INTO multi_add(Name, List)
SELECT Name, List
FROM multi_add
Unfortunately when I try to build a RUN button using scriptcase 7 and add this code to the OnFinish it does not work.
After a lot of review I found that using the OnRecord code for inserting data into a different table in the OnFinish area of the run button, seems to work for this scenario, however, I can’t seem to get the data to populate with what I need it to. It will create a new record, with a new ma_id but Name and List are either blank or whatever I type into the array. Here is the code:
$insert_table = ‘multi_add’; // Table name
$insert_fields = array( // Field list, add as many as needed
‘Name’ => ‘Name’,
‘List’ => ‘List’,
);
// Insert record
$insert_sql = ‘INSERT INTO ’ . $insert_table
. ’ (’ . implode(’, ‘, array_keys($insert_fields)) . ‘)’
. ’ VALUES (’ . implode(’, ', array_values($insert_fields)) . ‘)’;
sc_exec_sql($insert_sql);
I have tried creating global variables, adding brackets and a whole lot more with no luck. I know I’m missing something and it’s probably going to be one of those duh moments but could someone please help? I need a fresh set of eyes.
Thanks in advance!
I actually did review that post earlier today, along with a variety of other posts, videos and tutorials lol. Tried to figure it out before I posted. I did copy and paste the first set of basic code information you gave him. Not sure what I did wrong with it earlier but I’ll show you what I tried with your post. Maybe you can make some sense out of the error:
Quitting for the night, been at it all day. At one point 4 records turned into 400 because it held the criteria. Even tried adding a reset to 0 for the count and it said NO and gave me more data lol. Oh well, any suggestions you guys could share would be greatly appreciated! Thanks!