PHP inside javascript

Questions related to customising nuBuilder Forte with Javascript or PHP.

PHP inside javascript

Postby Janusz » Thu Mar 07, 2019 9:47 pm

Hi,
I would like to place PHP code inside the javascript:
For example the following code place inside the PHP before save is adding one row to the table:
Code: Select all
$t="INSERT INTO parts(par_sample_id_number,par_req_nr) VALUES ('test1','req1')";
$x=nuRunQuery($t);

is it possible to execute equivalent code from javascript I mean to have someting which I could use for example in the buton /custome code / java script / onclick option.
Belowe just a not working sketch of what I would like to achieve:
Code: Select all
var a1 =  $t="INSERT INTO parts(par_sample_id_number,par_req_nr) VALUES ('test1','req1')";    ????
var a2 =  $x=nuRunQuery($t);     ???

var a = a1 + a2;   ???
nuRunPHPHidden(a, '');
Janusz
 
Posts: 229
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: PHP inside javascript

Postby kev1n » Thu Mar 07, 2019 11:42 pm

Hi,

Create a new (PHP) procedure (Builders -> Procedure).

Code: INSERT_INTO_PARTS
Description: Whatever...
Run: Hidden
PHP:
nuRunQuery("#INSERT_INTO_PARTS#");


In Javascript, call the procedure like this:

Code: Select all
var q = "INSERT INTO parts(par_sample_id_number,par_req_nr) VALUES ('test1','req1')"; 
nuSetProperty("INSERT_INTO_PARTS", q);
nuRunPHPHidden('INSERT_INTO_PARTS', 1);
kev1n
 
Posts: 271
Joined: Mon Oct 15, 2018 2:13 am

Re: PHP inside javascript

Postby Janusz » Fri Mar 08, 2019 6:44 am

Thanks a lot.

(and some small adjustment to the quotation marks)
Code: Select all
nuRunQuery('#INSERT_INTO_PARTS#');


Code: Select all
var q = "INSERT INTO parts (par_sample_id_number,par_req_nr) VALUES ('test1','req1')";  nuSetProperty('INSERT_INTO_PARTS', q);nuRunPHPHidden('INSERT_INTO_PARTS', 1);
Janusz
 
Posts: 229
Joined: Fri Dec 28, 2018 10:11 pm
Location: Krakow, Poland

Re: PHP inside javascript

Postby kev1n » Fri Mar 08, 2019 4:20 pm

Just be careful with it, because any sql statement can be passed by manipulating the javascript. Also delete and update statements.
I wouldn't pass whole sql-statements, just parts of it. And then put the whole statement together in the PHP part.
kev1n
 
Posts: 271
Joined: Mon Oct 15, 2018 2:13 am


Return to Custom Code



cron