Creating a form to insert data into a database

Daniel Mina
Daniel Mina used Ask the Experts™
on
Hi experts,
First of all, I'm not a web developer.
I have a web-host account, a SQL database and a domain name. I need to do the following Max by tomorrow :)
- I need a very simple form consists of 4 or 5 fields to insert data.
- A save button to save data in database.
Or any other method to do the same through my webpage.

Thanks in advance,
Daniel Mina
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
Well a form is simple https://www.w3schools.com/html/html_forms.asp
<form method="'post" acttion="somepage">
  First name:<br>
  <input type="text" name="firstname"><br>
  Last name:<br>
  <input type="text" name="lastname">
<button type="submit">Submit</button>
</form>

Open in new window

Just add more fields as needed.

The hard part is accepting data. You need to use a serverside language like .NET, PHP, Node etc.  Which language are you using and which sql database? MySQl, MSSQL or something else?

While the form code is easy, you should add other feature to prevent spam such as a captcha or honeypot. I found the honypot to work the best for me.

https://en.wikipedia.org/wiki/CAPTCHA
https://en.wikipedia.org/wiki/Honeypot_(computing)

Author

Commented:
Hi Scott,
Thanks a lot for your response, well I don't use any web development language as I mentioned before that I'm not a web developer but I have a very good experience in database. I use MS SQL server. I have a table for data to be inserted in but I need to know how.
David FavorFractional CTO
Distinguished Expert 2018

Commented:
You said, "First of all, I'm not a web developer."

Then best to use an existing CMS system like WordPress.

There is no way to answer your question without delving deeply into Web development... especially if you're writing custom code, because what you're asking is to re-develop a CMS like WordPress from scratch.

Form correctness will likely require session management.

Writing to your database will mean you must learn rudimentary HTML + PHP + MariaDB/MySQL.

What you're asking may seem simple + it's far more complex than you might imagine.

If you really think you must reinvent the wheel (WordPress or similar), then you'll begin by...

Answering all Scott's questions, which will start the process of evolving you into a Web Developer.
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Developer & EE Moderator
Fellow 2018
Most Valuable Expert 2013
Commented:
You need to start somewhere.  This is not really the place to ask for fully working ready made code from scratch.  Instead, we can help you get started or trouble shoot a piece of code that you do have.

I have given you the start for making a form.  HTML, CSS and Javascript are considered the front end of your site.  HTML is the base technology. CSS helps make it look good and javascript can help with some magic to make the page easier to use for your users. I suggest going through a course like https://www.codecademy.com/learn/learn-html to help get you starred.  Good resources are https://www.w3schools.com/html/ and https://developer.mozilla.org/en-US/docs/Learn/HTML.  The code I gave you is a good base.

Forms can send data via a GET or POST. You will see that in the method="post" https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Sending_and_retrieving_form_data. A GET is for sending data to a url like mysite.com/form.php?name=john&address=123%20maple&credit_card_number=1234567890123.  For obvious reasons, you don't want to send this type of information via a URL. For what you want you will use POST. Your serverside code will intercept the form data and start processing it.

The second part is accepting the data and accessing your database. As I said, you can use php, .NET, Nodejs and other languages to do this.  In php for instance, https://www.php.net/manual/en/tutorial.forms.php you can accept the first and last name fields like

$firstname = $_POST["firstname"];
$lastname = $_POST["lastname"];

Open in new window

Finally you will take this data to your database.  https://docs.microsoft.com/en-us/sql/connect/php/microsoft-php-driver-for-sql-server?view=sql-server-2017  You will use PDO to connect to the data and send an sql statement like you are used to your database.

That is a bit oversimplified. First you want to make sure the data you have is clean. Then ensure you have a good connection to the db. And finally run the insert.  There are more code examples on the MS site https://docs.microsoft.com/en-us/sql/connect/php/example-application-pdo-sqlsrv-driver?view=sql-server-2017 as well as php.net.

If you really just want a quick working form and not have to develop the code on your own, best to contact one of the Experts here directly. Otherwise, take this in bits. First the front end form. Then the back end in 3 parts. First will be accepting data. Second will be making sure you have good data. Third will be updating your database. You may need to ask multiple questions.
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
Hi Daniel,

Inserting data into a Database is pretty straight forward but you will need some development skills.

Basically there are 2 parts to your requirements. The first part is what's called the Client Side code. This is the front-facing part of your application - the bit that the user sees when they visit your site, and in your case, this would be a simple HTML form. You start with a <form> tag and set the method (how the data will be send to the server) and the action (where on the server it will be sent). You include form fields to allow your user to input data, and you add a Submit button. Scott's already shown you a basic setup for an HTML form.

The second part of your requirement is where your development skills come into play. This is called the Server Side code. This is the code that is responsible for taking the data from the form and inserting it into your database. To do this you will need to create a script using a server-side scripting language. There are several languages available to do this, such as PHP, C#, NodeJS etc., and which one you choose will depend on how your server is set up. You haven't given us that information so we can't give you a specific answer. Whichever one you choose though will effectively do the same thing - it will create a connection to your database, it will check the validity of the submitted data, and it will run a database query (INSERT INTO in your case). It will usually then generate a response that you can display to the user ("Data Updated OK" etc.)

If you let us know what server-side language you have available and exactly what Database server you're running (you say SQL, but is this MS SQL or MySQL??), we can give you more specific examples of what you need to do.

Author

Commented:
Thanks a lot guys for your detailed responses.

Hi Chris,
My web-host supports .net and database is MS-SQL.
Most Valuable Expert 2018
Distinguished Expert 2018

Commented:
OK. Then your server-side code is probably going to be done using ASP.NET, and if you're not a developer, then I would suggest that you're going to find this tricky - particularly if you have a deadline of today.

I would recommend that you edit your question and add the ASP.NET / C# topics to it as that will attract Experts with the suitable level of knowledge.

Author

Commented:
Done, Thanks a lot Chris.
Scott FellDeveloper & EE Moderator
Fellow 2018
Most Valuable Expert 2013

Commented:
I asked one of our .NET Experts try and assist here.
Chinmay PatelChief Technology Ninja
Distinguished Expert 2018

Commented:
Hi Daniel,

If your web host supports .net core (Most probably they should) then you can start with https://orchardproject.net/. I think that is the only Open Source CMS I see you can start using very quickly and get results. You don't need to be a developer but you will have to follow the instructions step by step, to set it up.

Also, if it is just a form and you need it for a temporary period, you can try Microsoft Forms PRO https://formspro.microsoft.com/en-us/, one month trial is free.

If that does not fit the bill and you are willing to shell out money then there are couple of commercial solutions as well, for example, http://www.composite.net/ but even those will require you to follow some steps to complete the setup.

PS: I am not mentioning classic Orchard, Umbraco, Telligent, BlogEngine etc. as they are bit more complex to setup but still are really great Open Source solutions.

PPS: Actually, if it is just 1 form with 5 fields, you could easily get someone on Fiver or Upwork to complete it for you at a nominal cost.

Regards,
Chinmay.

Author

Commented:
Thanks a lot guys, your responses were very helpful for me. I got a friend who managed this task as per your recommendations.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial