This topic is locked
[SOLVED]

 Tri-part events

10/6/2019 4:54:31 PM
PHPRunner General questions
K
keithh0427 author

I am trying to work with some buttons on a list page that is inserted with each record listed. The button is supposed to verify the user's intentions by asking them if they are sure they want to perform the function desired. That works. But, the desired function is not being performed.
Here is my code.
Client Before:

var r = confirm("Are you sure you want to unsubscribe this sacrament?");

if (r == true) {

params["unsubscribe"] = "Yes";

} else {

params["unsubscribe"] = "No";

}
Server:

global $conn;
$result["unsubscribe"] = $params["unsubscribe"];
IF($params["unsubscribe"] == "Yes")

{

$userName = Security::getUserName();

$today = date('Y-m-d');

$record = $button->getCurrentRecord();

$sql = "UPDATE recruit SET unsubscribed = 'Y', unsubscribedDate = now(), unsubscribedBy = '" . $user . "', WHERE recruitID = '" . $record["recruitID"] . "'";

$db_exec($sql, $conn);

}
The Client Before is working. The Server is not. I've checked the $sql by plugging in the correct values and it does work.
I've got something wrong somewhere, but can't seem to figure it out.

Sergey Kornilov admin 10/6/2019

The most obvious issue us that you are using $user variable in your SQL Query that is not defined anywhere.
You need to follow the basic troubleshooting steps i.e. print your SQL Query instead of executing it. Check the article on troubleshooting custom buttons in PHPRunner manual.

K
keithh0427 author 10/7/2019

You are right about the $user and $userName. I had changed the userName variable in the code, but forgot to change the post on here. My apologies.
I read through the debugging section that you mentioned and even ran the script through a debugger. I could not find the issue.
I have tried echoing the sql statement and then exit the program, but it doesn't display and it doesn't exit the script. I placed it in the "Server" part as:
echo $sql;

return false;

exit();
But, again, that did not show the sql statement and it didn't exit the script either.
So, I moved to the following to the Server part of the button:
$today = date("Y-m-d"); // This did show the correct date when I ran the debugger

$result["unsubscribe"] = $params["unsubscribe"]; // this actually does work when I use the Before area of the button..

$button->getCurrentRecord(); // this works as well. The debugger gave showed me the correct recruitID as the result
IF($result["unsubscribe"] == "Yes")

{

$data = array();

$keyvalues = array();

$data["unsubscribed"] = "Y";

$data["unsubscribedDate"] = $today;

$data["unsubscribedBy"] = Security::getUserName();

$keyvalues["recruitID"] = $button["recruitID"];

DB::Update("recruit", $data, $keyvalues );

}
Next, I removed the Before and After scripts and placed the following in the Server part:
$today = date("Y-m-d"); // This did show the correct date when I ran the debugger

$button->getCurrentRecord(); // this works as well. The debugger gave showed me the correct recruitID as the result
$data = array();

$keyvalues = array();

$data["unsubscribed"] = "Y";

$data["unsubscribedDate"] = $today;

$data["unsubscribedBy"] = Security::getUserName();

$keyvalues["recruitID"] = $button["recruitID"];

DB::Update("recruit", $data, $keyvalues );
This didn't work either. But, shouldn't this last bit of code work in the Server part of the button withoutthe Before and After javascript parts?

C
Corrie 10/8/2019

Change the $db_exec to just db_exec. (Without the $ sign)



I am trying to work with some buttons on a list page that is inserted with each record listed. The button is supposed to verify the user's intentions by asking them if they are sure they want to perform the function desired. That works. But, the desired function is not being performed.
Here is my code.
Client Before:

var r = confirm("Are you sure you want to unsubscribe this sacrament?");

if (r == true) {

params["unsubscribe"] = "Yes";

} else {

params["unsubscribe"] = "No";

}
Server:

global $conn;
$result["unsubscribe"] = $params["unsubscribe"];
IF($params["unsubscribe"] == "Yes")

{

$userName = Security::getUserName();

$today = date('Y-m-d');

$record = $button->getCurrentRecord();

$sql = "UPDATE recruit SET unsubscribed = 'Y', unsubscribedDate = now(), unsubscribedBy = '" . $user . "', WHERE recruitID = '" . $record["recruitID"] . "'";

$db_exec($sql, $conn);

}
The Client Before is working. The Server is not. I've checked the $sql by plugging in the correct values and it does work.
I've got something wrong somewhere, but can't seem to figure it out.