I'm getting into HTML and PHP lately and there's one thing i can't wrap my head around:
What is the correct/best way to load data from a html-form into a MySQL-Database? I checked out the w3schools tutorial and multiple links but I'm still confused. They never really mention JavaScript to be necessary there but to whomever I talk always says something bout JavaScript to read data from forms. So here's how I see it:
- You can create a form element in your html-file and add the action="path/to/script.php and method="post/get". Then you define the different textfields, radiobuttons, e.g. that are supposedly part of the form and add a unique name attribute to each one. Then at the end you implement a button type="submit" element at the end of the form. As soon as the user will hit the submit button, all the data filled in by the user will be accessible through the superglobal variable $_GET or $_POST. All that is left is to use the php-script to set up a db connection, prepare a statment and bind parameters to it. Then I can simply access all the objects of the associative array and replace the statement wildcards with them until I got all elements.
In case the concept is correct, would it be possible to add multiple submit buttons and bind their action to different php scripts depending on which button they chose, right? Independent on it being correct or not, where should/does JavaScript come into play? How would the story look like if I were to use JavaScript. When do I have to use JavaScript to get the data using the id attribute (document.getElementById("uniqueID").value)? Is it if I want to access non-form data from withing my html-document?
I'm short on time else I'd test it myself, but I'm pretty sure someone has already done it aaand understood it as well. So thank you for answering :)
EDIT: I might've found a use case where you need JavaScript. And that's when you're trying to get the selected value from a radiobutton field. (I think) EDIT EDIT: You don't need JS to read the value of a radiobutton. Just make sure you put the name tag in the select tag or all of the radiobuttons if you don't make it into a dropdown.