Since javascript is a client side language if is not possible to directly use them. You can however use AJAX to transfer values of those JS variables to the server. Execute your sql statement and return back the results in some JSON object for example.
HTH :)
Oki so say we have the following in JS
var myvar1 = "HELLO WORLD 1";
var myvar2 = "HELLO WORLD 2";
Now we want to send myvar to the server via AJAX. Here is how.
$.ajax({
type: "POST",
url: "some.php",
data: ({'action' : 'action1' , 'myvar1' : myvar1 , 'myvar2' : myvar2 }),
success: function(msg){
alert( "Data Saved: " + msg );
}
});
The url must be some script that will handle the ajax request. What will be echoed by that script will end up in the msg variable of the success callback.
AJAX Handler
To do this you will need to send an extra parameter with each AJAX request. If you look at the above example I added the action parameter. This will allow us to identify which action should be executed by the AJAX Hander.
ajaxhandler.php
switch($_POST["action"]) {
case "action1":
action1($_POST["myvar1"]);
break;
case "action2":
action2($_POST["myvar2"]);
break;
}
function action1($myvar1){
do your action logic here
}
function action2($myvar2){
do your action logic here
}