[Solved] How can we get value in php variable from javascript variable


PHP is processed on the server, before sending the result to the client.

For example, if you do this:

<p>
<?php
$name = "Dan";
print "hello, $name, ";
?>
How are you?
</p>

The client will get:

<p>hello, Dan, How are you?</p>

And then, the client will process any javascript included in the code.

So in your case, the server would try to process this code:

<?php $n ?>

and then send the result to the server, appending the code out of the tags. Which would give an error, since $n by itself is not a valid php instruction.

So: PHP is executed on the server, and then, javascript is executed on the client.

You should check some tutorials, and try first to understand how PHP and Javascript work.

http://www.webmonkey.com/2010/02/php_tutorial_for_beginners/

http://www.tutorialspoint.com/php/php_introduction.htm

solved How can we get value in php variable from javascript variable