Page 1 of 1

PHP inside javascript

Posted: Thu Mar 07, 2019 1:17 pm
by Janusz
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, '');

Re: PHP inside javascript

Posted: Thu Mar 07, 2019 3:12 pm
by kev1n
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);

Re: PHP inside javascript

Posted: Thu Mar 07, 2019 10:14 pm
by Janusz
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);

Re: PHP inside javascript

Posted: Fri Mar 08, 2019 7:50 am
by kev1n
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.