Change ID field on save

Questions related to using nuBuilder Forte.

Change ID field on save

Postby Wesleyitguru » Fri Sep 06, 2019 6:47 pm

Hi All,

I'm busy setting up a simple incident logger for a client. The idea is that they can log a incident and on save it emails the client. I have two tables setup up. One for the incidents and one for the clients. The problem is I'm not able to pull the email address from the client table on the php. Here is my Table structure:
Table 1: ipcamclient
ipcamclient_id
ipcamclient_name
ipcamclient_company
ipcamclient_email

Table 2: ipcam_incidents
ipcam_incidents_id
ipcamincident_num
ipcamincident_date
ipcamincident_hour
ipcamincident_client - This is a lookup on the client table, which gives me the unique ID from ipcamclient_id Which I have manually changed to the client email address via phpmyadmin.
ipcamincident_report

My Email script is:
Code: Select all
$to = "#ipcamincident_client#";
$from = "alerts@**.com";
$fromname = "IPCameraSolutions Alerts";
$content = "Incident details\n
Client:#ipcamincident_client#\n
Date:#ipcamincident_date#\n
Time:#ipcamincident_hour#\n
Incident:\n
#ipcamincident_report#\n";
$subject = "New Incident reported";
$html = false;

$sm = nuSendEmail($to, $from, $fromname, $content, $subject, $html);


The simplest solution to me is just to change the
Code: Select all
ipcamclient_id
to be the clients email, can this be done via a php command on After save? Alternatively how can I pull the clients email from the client table in my php command?
Wesleyitguru
 
Posts: 7
Joined: Thu Jul 05, 2018 11:15 pm

Re: Change ID field on save

Postby kev1n » Fri Sep 06, 2019 10:41 pm

Hi,

Something like this should do the job (untested):

Code: Select all

$to = "#ipcamincident_client#";
$email = getEmailAddress($to);

$from = "alerts@**.com";
$fromname = "IPCameraSolutions Alerts";
$content = "Incident details\n
Client:#ipcamincident_client#\n
Date:#ipcamincident_date#\n
Time:#ipcamincident_hour#\n
Incident:\n
#ipcamincident_report#\n";
$subject = "New Incident reported";
$html = false;

$sm = nuSendEmail($to, $from, $fromname, $content, $subject, $html);


function getEmailAddress($Id) {
   $sql = "
      SELECT `ipcamclient_email` FROM `ipcamclient` WHERE `ipcamclient_id` = '$Id'
   ";
   
   $result = nuRunQuery($sql);
   $arr = db_fetch_row($result);
   return $arr[0];   
}
kev1n
 
Posts: 244
Joined: Mon Oct 15, 2018 2:13 am

Re: Change ID field on save

Postby Wesleyitguru » Wed Sep 11, 2019 10:55 pm

kev1n wrote:Hi,

Something like this should do the job (untested):

Code: Select all

$to = "#ipcamincident_client#";
$email = getEmailAddress($to);

$from = "alerts@**.com";
$fromname = "IPCameraSolutions Alerts";
$content = "Incident details\n
Client:#ipcamincident_client#\n
Date:#ipcamincident_date#\n
Time:#ipcamincident_hour#\n
Incident:\n
#ipcamincident_report#\n";
$subject = "New Incident reported";
$html = false;

$sm = nuSendEmail($to, $from, $fromname, $content, $subject, $html);


function getEmailAddress($Id) {
   $sql = "
      SELECT `ipcamclient_email` FROM `ipcamclient` WHERE `ipcamclient_id` = '$Id'
   ";
   
   $result = nuRunQuery($sql);
   $arr = db_fetch_row($result);
   return $arr[0];   
}

No Luck, something maybe missing? My coding skills are sketchy, so I've reached the limit of where I think I go tinker.
Wesleyitguru
 
Posts: 7
Joined: Thu Jul 05, 2018 11:15 pm

Re: Change ID field on save

Postby kev1n » Wed Sep 11, 2019 11:26 pm

I've added a few nuDebug() calls. Run the code again and then check the debug log and show me what you see.

Code: Select all
$to = "#ipcamincident_client#";

nuDebug("To: ".$to);

$email = getEmailAddress($to);

nuDebug("Email: ".$email);

$from = "alerts@**.com";
$fromname = "IPCameraSolutions Alerts";
$content = "Incident details\n
Client:#ipcamincident_client#\n
Date:#ipcamincident_date#\n
Time:#ipcamincident_hour#\n
Incident:\n
#ipcamincident_report#\n";
$subject = "New Incident reported";
$html = false;

$sm = nuSendEmail($to, $from, $fromname, $content, $subject, $html);

nuDebug($sm);

function getEmailAddress($Id) {
   $sql = "
      SELECT `ipcamclient_email` FROM `ipcamclient` WHERE `ipcamclient_id` = '$Id'
   ";

   nuDebug($sql);
   
   $result = nuRunQuery($sql);
   $arr = db_fetch_row($result);
   return $arr[0];   
}
kev1n
 
Posts: 244
Joined: Mon Oct 15, 2018 2:13 am

Re: Change ID field on save

Postby Wesleyitguru » Thu Sep 12, 2019 12:31 am

2019-09-11 16:56:34 - After Save of Form incidents line 20
Code: Select all
[0] : To: 5d790b0f99c6a57

2019-09-11 16:56:34 - After Save of Form incidents line 46
Code: Select all
[0] :
      SELECT `ipcamclient_email` FROM `ipcamclient` WHERE `ipcamclient_id` = '5d790b0f99c6a57'

2019-09-11 16:56:34 - After Save of Form incidents line 24
Code: Select all
[0] : Email: wesley@***.com.na
Hid the email address, but it is pulling the correct email.
2019-09-11 16:56:34 - After Save of Form incidents line 39
Code: Select all
[0] : Array
(
    [0] =>
    [1] => Message sent successfully
)


I don't see the message come through though.
Wesleyitguru
 
Posts: 7
Joined: Thu Jul 05, 2018 11:15 pm

Re: Change ID field on save

Postby Wesleyitguru » Thu Sep 12, 2019 12:37 am

All fixed. Needed to specific $email in the mail portion and not $to
Code: Select all
$to = "#ipcamincident_client#";

nuDebug("To: ".$to);

$email = getEmailAddress($to);

nuDebug("Email: ".$email);

$from = "alerts@**.com";
$fromname = "IPCameraSolutions Alerts";
$content = "Incident details\n
Client:#ipcamincident_client#\n
Date:#ipcamincident_date#\n
Time:#ipcamincident_hour#\n
Incident:\n
#ipcamincident_report#\n";
$subject = "New Incident reported";
$html = false;

$sm = nuSendEmail($email, $from, $fromname, $content, $subject, $html);

nuDebug($sm);

function getEmailAddress($Id) {
   $sql = "
      SELECT `ipcamclient_email` FROM `ipcamclient` WHERE `ipcamclient_id` = '$Id'
   ";

   nuDebug($sql);
   
   $result = nuRunQuery($sql);
   $arr = db_fetch_row($result);
   return $arr[0];   
}
Wesleyitguru
 
Posts: 7
Joined: Thu Jul 05, 2018 11:15 pm

Re: Change ID field on save

Postby kev1n » Thu Sep 12, 2019 12:38 am

:D
kev1n
 
Posts: 244
Joined: Mon Oct 15, 2018 2:13 am

Re: Change ID field on save

Postby admin » Tue Sep 17, 2019 10:53 am

.
admin
Site Admin
 
Posts: 3108
Joined: Mon Jun 15, 2009 9:53 am


Return to General