Save data of form to database with jquery, ajax and php
Hello everyone!
I am working on a website which needs to collect some type of data from the visitors and then send it to a database/file.
I did an example to illustrate:
So, on the left I have a form so the users can submit their company's name and annual income. Then I have a counter that after processing the data will update the values.
What I need here is instead of the form data goes to an email, I need the data to be sent to a database or file and then the same data will update the values of the number of companies that submited the form and the accumulated annual income of all companies.
So, I have a simple setup (with my limited knowledge of jquery/php), that sends the data from the form to a php file that writes the data to a simple .txt file(data.txt).
I would like to ask if this aproach is relaiable and secure and how would I send the data for a database and then grab the values and update the counters with no manual editing.
Also, I would need the submitted data rendered in an html page so the admin of the site can see the submited companies and have that reference. This page needs to be secure, so only the admin can see it.
This is my first question, not sure if I am following the protocol, and if I am asking too much. Thank you and sorry for my bad english
-The code I have so far is working, but should/can I improve it or it's ok like this?
-Also, see the image again:
I need the values of "Number of companies" to be updated with the number of entries in the Database.
And the "Accumulated annual income" to be also updated, adding up all the anual incomes, if I have 2 entries in the database with the annual incomes being 5 in one and 4 in other, the value should be added up and rendered in html as "9", where is 0 now.
How would I replace these "dummy" numbers with the number returned from the MySQL SUM() function?
-Let's say in the beggining the number returned from the mysql sum is "1256"; I need to keep the zeros on the left and only affect the 4 numbers on the right. How would I do that?
http://www.jstiles.com/Blog/How-To-Submit-a-Form-with-jQuery-and-AJAX
http://stackoverflow.com/questions/10584370/how-can-i-pass-data-from-jquery-to-php-for-saving-into-a-database