Now that I look at it, it makes more sense as to why you are having problems.....
The php code is going to be executed before your html page is rendered. So you end up with
<a href="test.php" onclick="">hello hello</a>
The onClick is empty because your function doesn't do anything but assign one variable to another variable.