This topic is locked
[SOLVED]

 Need Help with a Button

10/24/2013 1:08:16 PM
PHPRunner General questions
S
stiven author

Hi Everyone,
I need help with a button please. Maybe some one can help me. I used the example from the manual called "Email selected records", but what I really need is to insert those selected records into another table. I modified the code but it didn't work. Here is the code.
Thanks for your help.



global $dal;

$dal_TableName = $dal->Table("ies_case_log");

$body="";

foreach(@$keys as $keyblock)

{

$arr=explode("&",refine($keyblock["log_id"]));

if(count($arr)<1)

continue;

$arr2=array();

$arr2["log_id"]=urldecode(@$arr[0]);

$where = KeyWhere($arr2);

$rstmp = $dal_TableName->Query($where,"");

$datatmp=db_fetch_array($rstmp);

$sql = "INSERT INTO coor_case_log (log_id,case_no,log_date,client_name,log,done_by) VALUES ('".$datatmp['log_id']."','".$datatmp['case_no']."','".$datatmp['log_date']."',

'".$datatmp['client_name']."','".$datatmp['log']."','".$datatmp['done_by']."')";

db_exec($sql,$conn);

$body .= "Case No." . $datatmp['case_no']. "\n";

$body .= "Client Name." . $datatmp['client_name']. "\n";

$body .= "Log Date: " . $datatmp['log_date'] . "\n";

$body .= "Notes: " . $datatmp['log'] . "\n";

$body .= "Done By: " . $datatmp['done_by'] . "\n-----------\n\n";

}



// send the email

$email="joanb@iessi.com";

$subject="Testing Notes";

$arr = runner_mail(array('to' => $email, 'subject' => $subject,

'body' => $body));

$result["txt"] = "Files Notes Were Transferred";



// if error happened print a message on the web page

if (!$arr["mailed"])

{

$errmsg = "Error happened:
";

$errmsg.= "File: " . $arr["errors"][0]["file"] . "
";

$errmsg.= "Line: " . $arr["errors"][0]["line"] . "
";

$errmsg.= "Description: " . $arr["errors"][0]["description"] . "
";

$result["txt"] = $errmsg;

}
Sergey Kornilov admin 10/24/2013

As a first step make sure your code doesn't produce any errors. Here is article that explains how to access error messages produced by button's server side code:

http://xlinesoft.com/phprunner/docs/troubleshooting_custom_buttons.htm

S
stiven author 10/24/2013

I was getting an error in the chrome console "JSON parse error" I modified the code to use DAL and its working now, here is the result



global $dal;

$dal_TableName = $dal->Table("ies_case_log");

$body="";

foreach(@$keys as $keyblock)

{

$arr=explode("&",refine($keyblock["log_id"]));

if(count($arr)<1)

continue;

$arr2=array();

$arr2["log_id"]=urldecode(@$arr[0]);

$where = KeyWhere($arr2);

$rstmp = $dal_TableName->Query($where,"");

$datatmp=db_fetch_array($rstmp);
$coor_log = $dal->Table('coor_case_log');

$coor_log->log_id = $datatmp['log_id'];

$coor_log->case_no = $datatmp['case_no'];

$coor_log->log_date = $datatmp['log_date'];

$coor_log->client_name = $datatmp['client_name'];

$coor_log->log = $datatmp['log'];

$coor_log->done_by = $datatmp['done_by'];

$coor_log->Add();

}



$result["txt"] = "Files Notes Were Transferred";