Updated :
This doesn't Work because :
$myphpvar = "<script>document.write(localStorage.getItem('myjsvar'));</script>";
Now your PHP $myphpvar
variable contains :
<script>document.write(localStorage.getItem('myjsvar'));</script>
when you echo
then this is like :
echo "<script>document.write(localStorage.getItem('myjsvar'));</script>"
so this will show your Js variable,because it runs on your browser.
but when you do this in SQL : it look something like below :
$sql="INSERT INTO `pending` (`id`, `myfield`) VALUES ('', '<script>document.write(localStorage.getItem('myjsvar'));</script>')";
For Achieving this, you have to pass your localStorage
value to URL
,and get it on PHP
or use AJAX
to post!
window.location.href = window.location.href+"?local="+localStorage.getItem('myjsvar'));