0

One of my HTML pages saves inputs from the user and stores them in local storage. For the purpose of this question I will refer only to my fName variabe. Input is taken and saved in local storage on one html page as follows.

    function writeFName() {


    first_name = document.querySelector('#fName_Input').value;

    localStorage.setItem('fName', first_name);

    var cfmF = confirm("Did you mean to enter: \n" + first_name + '?');

    if (cfmF) {
        console.log(first_name);
        window.alert('Success!');

        first_name = localStorage.getItem('fName');
    } else {
        window.alert('Please Re-Enter First Name');
    }
}

The issue lies in that I want to use my PHP file, edBase.php to take this input, and pass it to my SQL database. I am completely at a loss as to how I parse fName variable from localstorage in my php file. I know how to write to the SQL database but how I write with a html input from another page is completely unknown to me.

Many thanks.

cola465
  • 113
  • 8
  • How does the user get to `edBase.php`? – user3783243 Jan 19 '20 at 14:30
  • a href in my navbar. – cola465 Jan 19 '20 at 14:32
  • You could add an `onclick` and append the values to the `href` so they are in `GET`. – user3783243 Jan 19 '20 at 14:36
  • so Onclick I pass the variables to my database through SQL in the onclick function? Wouldn't that mean changing my html file to a php file – cola465 Jan 19 '20 at 14:37
  • `onclick` is JS, not PHP. You can keep it as HTML no PHP is required for this. Something like ` – user3783243 Jan 19 '20 at 14:38
  • So how do I pass the values in a GET in the href? Complete html js and php noob only been learning it for a few days – cola465 Jan 19 '20 at 14:39
  • If using jquery could do something like https://stackoverflow.com/questions/179713/how-to-change-the-href-for-a-hyperlink-using-jquery or you could just cancel the `a` action and submit it as a new request with `window.location.href` in the js function – user3783243 Jan 19 '20 at 14:43
  • No for some reason the php file is just not picking up my JS inputs no matter what I do to it. I think the best way for you to help is to create a working fiddle or file without all the other code where a js variable is posted to a php script and echoed in that php script to make sure it works – cola465 Jan 21 '20 at 10:23
  • then I can work from adding my own code into that code in a segmented manner until I find what part of it is making the code unable to run – cola465 Jan 21 '20 at 10:24
  • I have created a couple test files to demonstrate my problem. To my understanding when I run [test1.html](https://codeshare.io/5o1QZb) it is to my understanding that [test.php](https://codeshare.io/am1pZ0) should output to the console the str variable which has value 'padw' However when I press the no css horrible lonely looking button I created I see no output in the console, no errors, nothing. Do I need to return the php variable to the html or something? I just want to ensure that the php code is recieving the html variable as all I'm really trying to do is save user inputs to a database. – cola465 Jan 21 '20 at 10:43

0 Answers0