javascript - Passing HTML5 Local Storage Value to PHP error -
this question has answer here:
i using html5 local storage , trying read , pass php variable:
this code:
$myphpvar = "<script>document.write(localstorage.getitem('myjsvar'));</script>"; when this:
echo $myphpvar; the value looks right (at leave visually)
upto there looks when add code:
$sql="insert `pending` (`id`, `myfield`) values ('', '$myphpvar')"; i error:
error: have error in sql syntax; check manual corresponds mysql server version right syntax use near ..
the error points here:
$myphpvar = "<script>document.write(localstorage.getitem('myjsvar'));</script>"; any ideas why?
updated :
this doesn't work because :
$myphpvar = "<script>document.write(localstorage.getitem('myjsvar'));</script>"; now php $myphpvar variable contains :
<script>document.write(localstorage.getitem('myjsvar'));</script> when echo :
echo "<script>document.write(localstorage.getitem('myjsvar'));</script>" so show js variable,because runs on browser.
but when in sql : below :
$sql="insert `pending` (`id`, `myfield`) values ('', '<script>document.write(localstorage.getitem('myjsvar'));</script>')"; for achieving this, have pass localstorage value url,and on php or use ajax post!
window.location.href = window.location.href+"?local="+localstorage.getitem('myjsvar'));
Comments
Post a Comment