![]() |
|
|
Form to database Tutorial in ASPDownload the codeWe are going to create 2 pages. The first will display a simple HTML form and the second will be an ASP page (known as the action page) which will process the data sent by the form and insert it into our Access database. We will be using a DSN-less connection. Create a page and name it 'form.html'. Copy the following code into it. <html> The above code creates a simple form asking for name, email and
comments. Now onto the ASP action page, i.e. the page that will receive the details sent from the form and process them. Create a new ASP page called 'add_to_database.asp'. Keep it in the same folder as 'form.html'. Copy and paste the following ASP code into 'add_to_database.asp'. <%@ Language="VBScript" %> Here's how to create a simple Access database to work with this tutorial. We will create a simple Access database with just one table 'users_tbl' containing four fields, 'id', 'name', 'email', 'comments' respectively. Creating an access database is pretty straightforward. Open Microsoft Access and create a database 'users.mdb' and save it in the same directory where you are creating other HTML and ASP files for this tutorial. In 'design view' of Microsoft Access our 'users_tbl' table will look like : ![]() Notice at the bottom that we have set the 'Allow Zero Length' to Yes, this will allow the form to pass empty strings, i.e. not entering a value for any of the textfields. Run the example submitting your form details and it will insert those values into our Access database. Just note that if you enter the ' (an apostrophe) it will not work. We will come to dealing with that a little later on. Well it's as simple as that, but now you'll want to see what you have entered. In our next tutorial we will create a page that will display the records that you have just entered.
Site developed by Michael Wall - Web Design Belfast N.Ireland. |
|