Welcome to the nuBuilder Forums!

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

PHP inside javascript

Questions related to customising nuBuilder Forte with JavaScript or PHP.
Post Reply
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

PHP inside javascript

Unread post 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, '');
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: PHP inside javascript

Unread post 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);
Janusz
nuBuilder Team
Posts: 506
Joined: Fri Dec 28, 2018 1:41 pm
Location: Krakow, Poland
Has thanked: 8 times
Been thanked: 18 times

Re: PHP inside javascript

Unread post 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);
If you like nuBuilder, please leave a review on SourceForge
kev1n
nuBuilder Team
Posts: 4305
Joined: Sun Oct 14, 2018 6:43 pm
Has thanked: 71 times
Been thanked: 446 times
Contact:

Re: PHP inside javascript

Unread post 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.
Post Reply