I am trying to get a variable from session storage and use it in my PHP MySQL query, but it keeps returning no values.
My JavaScript to get variables from session storage:
var myEmail = sessionStorage.getItem('myEmail');
Assigning a JavaScript variable to a PHP variable:
<?php
$emailAddress = "<script>document.write(myEmail);</script>";
?>
And once connected to the database:
<?php
$query = mysql_query("SELECT * FROM myTable WHERE emailaddress='$emailAddress';
?>
Can anyone see any problems? When I output the result it is just blank. Just before I make the query I echoed the email address and it output fine. Not sure when I put it in the query it just returns nothing. If i change the $emailAddress
in the query for "someone@gmail.com" for example it works fine, just not with the variable.