Page 1 of 1

Change ID field on save

Posted: Fri Sep 06, 2019 11:17 am
by Wesleyitguru
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?

Re: Change ID field on save

Posted: Fri Sep 06, 2019 3:11 pm
by kev1n
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];	
}

Re: Change ID field on save

Posted: Wed Sep 11, 2019 3:25 pm
by Wesleyitguru
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.

Re: Change ID field on save

Posted: Wed Sep 11, 2019 3:56 pm
by kev1n
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];   
}

Re: Change ID field on save

Posted: Wed Sep 11, 2019 5:01 pm
by Wesleyitguru
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.

Re: Change ID field on save

Posted: Wed Sep 11, 2019 5:07 pm
by Wesleyitguru
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];   
}

Re: Change ID field on save

Posted: Wed Sep 11, 2019 5:08 pm
by kev1n
:D

Re: Change ID field on save

Posted: Tue Sep 17, 2019 3:23 am
by admin
.