Welcome to the nuBuilder Forums!

Register and log in to access exclusive forums and content available only to registered users.

Change ID field on save

Questions related to using nuBuilder Forte.
Post Reply
Wesleyitguru
Posts: 7
Joined: Thu Jul 05, 2018 3:45 pm

Change ID field on save

Unread post 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?
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Change ID field on save

Unread post 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];	
}
Wesleyitguru
Posts: 7
Joined: Thu Jul 05, 2018 3:45 pm

Re: Change ID field on save

Unread post 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.
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Change ID field on save

Unread post 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];   
}
Wesleyitguru
Posts: 7
Joined: Thu Jul 05, 2018 3:45 pm

Re: Change ID field on save

Unread post 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.
Wesleyitguru
Posts: 7
Joined: Thu Jul 05, 2018 3:45 pm

Re: Change ID field on save

Unread post 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];   
}
kev1n
nuBuilder Team
Posts: 4307
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 448 times
Contact:

Re: Change ID field on save

Unread post by kev1n »

:D
admin
Site Admin
Posts: 2815
Joined: Mon Jun 15, 2009 2:23 am
Been thanked: 25 times

Re: Change ID field on save

Unread post by admin »

.
Post Reply