This tutorial will show you how to insert a rowof data into a database using ASP and an MS Access database. You can doit on one ASP file, but we'll have two files: one processor page(proc.asp), and one form page (form.asp). Then, we'll make the MSAccess database that corresponds to the ASP.Part I - Creating the processing page: proc.asp
This page will catch the form data, open a connection with the Accessdatabase (change "test.mdb" to your database), insert the row using asql query, and close the connection. If it executes fine, it will printout "done inserting row".
Here's the code:
<%Dim ConnDim SqlTempIf request("insrow") = "1" THENpsubject = request("pSubj")pdate = request("pDate")ptext = request("pText")Set Conn = Server.CreateObject("ADODB.Connection")Conn.connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("test.mdb")& ";" Conn.Open SQLTemp = "INSERT INTO tblTest (pSubj, pDate, pText) VALUES ('" & psubject & "', " & pdate & ", '" & ptext & "')"Conn.execute(SQLTemp)Conn.CloseSet Conn = Nothingresponse.write("<p>done inserting row</p>")End If%> |
Here's a simple form that will use the "post" method to submit the info to the proc.asp page:
<form name="frmInsert" method="post" action="test.asp"><input type="hidden" name="insrow" value="1">Subject: <input type="text" name="pSubj" size="13"><br>Date: <input type="text" name="pDate" size="13"><br>Text: <input type="text" name="pText" size="13"><br><input type="submit" size=8 value="Submit"></form> |
Make a table inthe database called "tblTest" (you may change it, but make sure itcorresponds with the above table name). Inside the database, make anAutonumber row called "pSubj" which is the Primary Key, a date rowcalled "pDate", and a row called "pText" with the memo row-type.
And there you have it, a database, a form, and a processor ready for data entry!
Note:Had trouble connecting to the database? Click here.
Related Articles
- Alternating Rows: MysqlThe first thing we need to do is connect to the database. I always put my db connection in a universal file, that way I can just change the variables once if I need to; but for the sake of the tutorial, im putting it in this file.
- MySQL TablesCreate, insert, update, delete, count and select rows in a database.
- Alternating Row ColorsTheres two different ways this can be done. The first is by getting results from a mysql query, the second is going through the values of an array. Ill go over both. First the full files (ill break it up into two files, one using mysql, and one using an array)
- Design an Online Chat Room with PHP and MySQLIn this article, you will learn how to design and develop a simple online chat room with PHP and MySQL. This tutorial explains every steps of the development, including both database design and PHP programming. Basic computer skills and knowledge of HTML and PHP are required. Ok, lets begin now. ....
- Alternating Rows: ArraysThe first thing we do here is echo out the html, again I wont go over this because theres really nothing to explain, except the css. We have two css classes, one for each of the alternating rows.
- PHP News CMSCheck out this great tutorial to find out all the details of Content Management Systems (CMS). Everything you need to know is right here.
- Users OnlineFirst Run this SQL In your MYSQL database..
- Image DatabasingThis tutorial teaches you how to upload images into a mysql database using PHP. Even though it sounds complicated, it is fairly simple and has many practical applications. One example of an application would be Forum User Images...
- PHP User StatsIn this tutorial I am going to teach you how to make a User Stats menu in PHP and MySQL which displays: Unique hits, Unique hits today, Total hits, Total hits today. If you dont have MySQL you can get one for free here.
- Alternating BackgroundsAlternate the backgrounds of table rows displayed from a MySQL database.
