0

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'"; ?> 
46
  • Welcome to Stack Overflow! Please visit the help center, take the tour to see what and How to Ask. Do some research, search for related topics on SO; if you get stuck, post a minimal reproducible example of your attempt, noting input and expected output using the [<>] snippet editor. Commented Jul 10, 2020 at 8:41
  • @mplungjan Updated my question to what I have tried, maybe you can look at that and tell me what I am missing? Commented Jul 10, 2020 at 8:44
  • PHP is on the server and JS is on the client. Please look at dupe and the links in the search I gave you Commented Jul 10, 2020 at 8:44
  • Also techdifferences.com/…. Commented Jul 10, 2020 at 8:45
  • @mplungjan I cant figure out why my code doesn't work. It looks fine to me. Commented Jul 10, 2020 at 8:50

0