I have a value stored in localstorage like this:
window.localStorage.setItem('name', document.getElementById("name_text").value);
When query the table, I want go query like this:
$query = "SELECT * FROM table WHERE user= "
I want to select from my table, where the user is equal to the value stored in localStorage. How can I do this?
I tried the following but no get no info from the table:
<script>
var keyName = window.localStorage.getItem('name');
</script>
<?php
$query = "SELECT * FROM table WHERE name='.$keyName.'"
?>
Test 1:
<script>
var name = window.localStorage.getItem('name');
$.ajax({
url: "index.php",
method: "POST",
data: { "name": name }
})
</script>
<?php
$name = $_POST['name'];
echo($name);
// prints 1
$query = "SELECT * FROM table WHERE name='$name'";
?>