0

I'm a beginner web developer, and I'm coding a small project, mostly in order to learn the practice.

I am now writing an HTML page (with JavaScript) that collects data from users. The HTML page is pretty complicated and by the time a user had finished filling all the fields, not all the data is in the form - some of it was calculated by JavaScript and stored, either in localstorage or in attributes of certain HTML elements.

How can I submit the data into a MySQL database? (using methods with POST in PHP, like this one, only allows to send data that is in <input> tags)

Community
  • 1
  • 1
yohai
  • 438
  • 5
  • 15

2 Answers2

1

you have to use ajax(Asychronous Javascript And Xml) to send data to the server or you can use jQuery to do it.. eg: $.ajax({ type: "get", url: some_php_script.php, data: {"list": list_data}, success: function(data){ do some work here with the data recieved } });

Akshay Takkar
  • 500
  • 1
  • 7
  • 21
1

You just need to send the values to a PHP script, then you can do whatever you want. You can use javascript to either:

  • Post the values via XmlHttpRequest, or "AJAX":
  • Add <input>s to your form with the proper values before submitting it (these can be hidden visually or with type="hidden")

If you are just getting started with PHP, MySQL, or really any language - try your best to avoid w3schools for information. The page you linked to has a classic example of SQL injection, and uses the deprecated mysql_* functions. See the PHP manual on Choosing an API before you get started.

Community
  • 1
  • 1
Wesley Murch
  • 101,186
  • 37
  • 194
  • 228