0

I am a little new to the inner workings of inputs and form actions. But I've been studying tirelessly trying to figure this out, maybe Im not researching the right way, but I am amazed at how little information there is on how to do a very common thing that I know is done all day everyday, with saving inputs like usernames and passwords. But again I want the usernames and passwords to stay visibly there once the save button is clicked on an individual input with an individual save button

So I am wanting to create several input fields on a php file webpage. These input will allow me and others working with me to store things like usernames, passwords, and other notes of sort.

let's start with this code.

<section>               
<div id="#" class="input-notediting">
   <input type="text" value="" id="first-input" class="input-notediting">
</div>
<button class="save-button" onclick="saveField()">
<i class="fa fa-floppy-o"></i>
</button> 
</section> 

1 input and 1 save button contained within section tags. And there may be more inputs contained within one section depending but..

I know many of you want to inform me of using a

<form method="post" action=""> 

to contain the inputs. And I'm not opposed to doing that, but I've seen other workarounds using ajax code for saving fields to a php script, to know that it may not be necessary.

I'm sorry this is all the code I essentially know how to work with at this point for my particular problem and question here.

But I'm pretty sure I need to use some jQuery to save the input data to a php file or a mySQL database table??

Basically how I want this to work is once the inputs are saved by a user clicking the save button, the value simply stays in the input field forever until another person changes the value or deletes it physically. I would also love for this to work with the click of a save button that wont refresh the page if possible or show any dialogue boxes at all or of a successful save either. Just want it clean and nice, trust that it is working and if I reload the page 2 days later the text I saved will still be there.

My research points me to many different types of solutions. Things like sort of a re - echo the contents of a mySQL table or the php file script variables into the

<input vale="<?php echo (""); ?>"> 

sorta maybe like this.

Other research points me to weird workarounds not all that suitable to my quest anyways, but require me to use a

<form method="post" action=""> 

to the php file script which again I am not opposed to doing if it works and is necessary but I would really prefer the page not to reload upon the submit action, but I tried that and then I for some reason can't get the form action to bring me back to the page I was on anyways, which stinks too, I know its done well all the time but I just don't know how to yet.

I would love for an advanced solution here. Thanks everyone.

Please please please help me out, I've got a large project to do on this and would be greatly appreciated, and always continue to learn everything I can. I am more or less an html and css expert, but dealing with forms and input functions and databases is a tiny bit new to me recently.

pgSystemTester
  • 8,979
  • 2
  • 23
  • 49

4 Answers4

0

There are various options to save the values of the input field. I will drop those methods so you can proceed your research on it -

  1. localStorage (JS only)
  2. PHP Session (PHP only)
  3. Cookies (available in both JS and PHP)
Saharsh
  • 1,056
  • 10
  • 26
  • Thanks youre awesome, I do not love the cookies Idea, but the other 2 I am interested in. –  May 25 '18 at 07:54
0

TM.

If you consider using AJAX in order to avoid refreshing your page, you should check out this post

Insert data through ajax into mysql database

I guess there might have even better solutions but that might be an entry point to what you're looking for.

Have a nice day

Ace

0

You need to get a good PHP/MySQL book. There are a number of non-trivial concepts that you need to become familiar with before you can tackle this project. The good news is that it is not particularly difficult, and can probably be grasped in the course of just a few days.

  • 1
    Thank you I am aware I need a better understanding, just part of the life learning process if you will, and however I dont feel your response was really all that helpful at all. if you would have responded with a good book to or tutorial to read, i still would have been dismayed a little but at least it would have been beneficial to the discussion here. –  May 25 '18 at 16:52
0

Not the advanced solution you asked but few tips :

If you want a button that doesn't refresh the page, give it the "button" type attribute : <button type='button'>

And be careful with <input value="<?php echo (""); ?>"> you're putting double quotes inside double quotes it will mess with your code !

Marvin T
  • 123
  • 8
  • Yes you are right there, I even mis-spelled vale supposed to be value but supposed to be –  May 25 '18 at 07:49
  • It was still understandable without a "u", don't worry ! (I edited my answer, don't know why a part of it wasn't showing) – Marvin T May 25 '18 at 07:50