This doesn't work as i see you expect it to. Javascript runs on the client side php on the serverside.

In this case you need to output the variable withjavascript to the browser. For instance in the form of a link with a GET variable. Ones that link is clicked the request is made to the server and php can get involved. Have a read here and here

So in a nutshell. you create alink with javascript that includes a GET variable. ones clicked php gets involved.

Any JavaScript will not run until the page is rendered in the browser, by which time PHP is no longer involved. You need to understand the distinction between client and server-side code: they are quite distinct, and run at differerent times.

language = "JavaScript" is obsolete; it should be:

Code:

<script type="text/javascript">
</script>

(although type is no longer essential). It is also generally accepted now that HTML tags should be in lowercase - it looks out-dated otherwise.

"The mysql extension is deprecated as of PHP 5.5.0, and is not recommended for writing new code as it will be removed in the future. Instead, either the mysqli or PDO_MySQL extension should be used." the docs

Perhaps if you give us a better idea of what you are trying to accomplish we can give you a better suggestion.

Php is executed before the page is pushed to the client and javascript is excuted as the page is loading in the browser (although it is often benificial to tell the browser to not execute it until the entire page is loaded) and after event on the loaded page.

The only way to get the variable back to the php interpreter is to call the page again passing variables, or use an ajax call to the server.

As your example is written it is easiest to simply do everything in javascript.