Page 1 of 1

UPDATE statement by pressing a button

Posted: Mon Nov 29, 2021 10:23 am
by marcus
Hello, I want to run a MySQL UPDATE statement by pressing a Button in nuBuilder and using Hash Cookies to modify the statement. What is the most simple way to achieve this?
Best Regards
marcus

Re: UPDATE statement by pressing a button

Posted: Mon Nov 29, 2021 10:38 am
by kev1n
Hi Marcus,

Add an onclick event to your button with a code like

Code: Select all

nuSetProperty('Your_Hash_Cooke','your string here');
nuRunPHPHidden('Your_Procedure_Name', 0);

Next, create a (PHP) Procedure with a code like:

Code: Select all

$hashCookie = "#Your_Hash_Cooke#";
nuRunQuery("UPDATE ...");

Re: UPDATE statement by pressing a button

Posted: Mon Nov 29, 2021 11:23 am
by marcus
Hello kev1n,
thanks for your reply, it works perfectly!
How can I pass on multiple hash cookies to the query?

Re: UPDATE statement by pressing a button

Posted: Mon Nov 29, 2021 11:36 am
by kev1n
Either by setting each Hash Cookie with nuSetProperty(), using a different hash cookie name

Code: Select all

nuSetProperty('Your_Hash_Cookie_1','your string here');
nuSetProperty('Your_Hash_Cookie_2','your other string here');
... or by using nuRunPHPHiddenWithParams()

Example:

Code: Select all

nuRunPHPHiddenWithParams('your_procedure_name_here', 'param', {param1: 'value1', param2: 'value2'}, 0);   

And in the PHP code, retrieve the parameters:

Code: Select all

$param = json_decode(base64_decode('#param#'));
$param1  = $param->param1;
$param2  = $param->param2;

Re: UPDATE statement by pressing a button

Posted: Tue Nov 30, 2021 10:28 am
by marcus
Hello kev1n, thank you very much! It works again perfectly!