Create a folder "phonebook" under c:/inetpub/wwwroot and save the following files . Then open the browser and type : http://localhost/phonebook/welcome.asp |
Create the following
MS Access Database Name of the mdb : phonebook.mdb Location : c:\inetpub\wwwroot\phonebook Table Name : phonebook_table Fields: name ..........Text(50) phoneno.................Text(35) record_id...............Auto Number |
<!--Save this file as menu_inc.asp--> <table align="center" cellpadding="5"> |
!-- save this file as
welcome.asp
--> <html> <head> <title>Welcome</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <!--#include file="menu_inc.asp"--> <table align="center"> <tr> <td align="center" style="font:bold 30px arial;color:#ff0000;"> Welcome to My Phone Book </td> </tr> </table> </body> </html> |
At this stage, you can test your program by opening the browser and typing: http://localhost/phonebook/welcome.asp |
<!--#include
file="open_conn_inc.asp"--> <!--Save this file as view.asp --> <html> <head> <title>View</title> <% sql="select * from phonebook_table order by Name" Set Rs=Server.CreateObject("ADODB.Recordset") Rs.Open Sql,Conn %> </head> <body> <!--#include file="menu_inc.asp"--> <% 'whenever a record is added or edited, this page will be opened 'with a request variable : postback_msg. We have to display the 'value of this postback_msg variable. If Request("postback_msg") <>"" Then 'if this variable is not empty %> <font color="red" size="4"><strong> <%=Request("postback_msg")%> </strong></font> <% End If %> <% If Rs.Eof Then Response.write("No Records present for Editing") Else %> <table border="1" align="center"> <tr> <th>Name</th> <th>Phone No.</th> </tr> <% While Not Rs.Eof %> <tr> <td> <%=Rs("name")%> </td> <td> <%=Rs("phoneno")%> </td> </tr> <% Rs.MoveNext Wend %> </table> <% End If %> </body> |
<% ' Save this file as : open_conn_inc.asp Set Conn=Server.CreateObject("ADODB.Connection") Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("phonebook.mdb") & ";" 'for aspspider web hosting, the following line is used. 'Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("..\..\database\phonebook.mdb") & ";" %> |
<% ' Save this file as adovbs.inc ' this is NOT a complete adovbs.inc file. ' lines NOT related to our project have been deleted. '---- CursorTypeEnum Values ---- Const adOpenForwardOnly = 0 Const adOpenKeyset = 1 Const adOpenDynamic = 2 Const adOpenStatic = 3 '---- LockTypeEnum Values
---- '---- CursorLocationEnum
Values ---- |
<!--Save this file
as : add.asp
--> <html> <head> <title>Add</title> </head> <body> <!--#include file="menu_inc.asp"--> <form action="add1.asp" Method="Post"> <table border="1" align="center"> <tr> <td> Name </td> <td><input type="text" name="name" size="40"> </td> </tr> <tr> <td> Phone No. </td> <td><input type="text" name="phoneno" size="12"> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value="Submit"> </td> </tr> </table> </form> </body> </html> |
<!--Save this file
as add1.asp--> <!--#include file="open_conn_inc.asp"--> <!--#include file="adovbs.inc"--> <% Set Rs=Server.CreateObject ("ADODB.Recordset") sql="select * from phonebook_table" 'Rs.CursorLocation=3 Rs.open sql,Conn, adOpenDynamic,adLockOptimistic 'If Rs.RecordCount > 20 Then ' Conn.Execute("delete from phonebook_table where record_id=(select min(record_rd) from phonebook_table)") 'End If ' The above 4 commented lines are not required for you. forget them. Rs.AddNew Rs("Name")=Request.Form("Name") Rs("PhoneNo")=Request.Form("PhoneNo") Rs.Update Response.Redirect("view.asp?postback_msg=Data Inserted Successfully") %> |
At this stage, you can test your program for adding a record. |
<!--Save this file
as edit.asp --> <!--#include file="open_conn_inc.asp"--> <% sql="select * from phonebook_table" Set Rs=Server.CreateObject("ADODB.Recordset") Rs.Open Sql,Conn %> <html> </body> |
<!--Save this file
as edit1.asp --> <!--#include file="open_conn_inc.asp"--> <% sql="select * from phonebook_table where record_id=" & Request("record_id") Set Rs=Conn.execute(sql) %> <html> <head> <title>Edit</title> </head> <body> <!--#include file="menu_inc.asp"--> <form action="edit2.asp" Method="Post"> <input type="hidden" name="record_id" value="<%=Request("record_id")%>"> <table border="1" align="center"> <tr> <td> Name </td> <td><input type="text" name="name" size="40" value="<%=Rs("name")%>"> </td> </tr> <tr> <td> Phone No. </td> <td> <input type="text" name="phoneno" size="12" value="<%=Rs("phoneno")%>"> </td> </tr> <tr> <td colspan="2" align="center"> <input type="submit" value="Update"> </td> </tr> </table> </form> </body> </html> |
<!-- Save this
file as edit2.asp --> <!--#include file="open_conn_inc.asp"--> <% conn.Execute("delete from phonebook_table where record_id=" & Record_id) Response.Redirect("view.asp?postback_msg=Record DELETED Successfully") %> |
Final Note: To reduce the number of coding lines to the barest minimum, the above program is NOT written in a perfect manner. For example certain things like form validation, closing of opened database connection,etc have been avoided. |
Phone Book - Complete ASP Coding
Labels:
ASP Code-PhoneBook
Contents In this Site
- actionscripts
- ASP Code-PhoneBook
- asp code-what you want to do model
- asp-insert-edit-del-in-one
- ASP.NET AT SYMBOL
- asp.net Oracle Connetivity
- DAP
- Google Map
- Home
- IP Address Qns
- Javascript:Close a window
- LAN VLAN Notes (Personal)
- Learn SDH
- Lifestyle
- Listener Control
- MANYCAM
- Mini Story-Send him to IIM
- Modem Config
- old asp: connection strings
- old asp: scriping
- ORACLE - PIVOT TABLE
- ORACLE- Database vs instance
- ORACLE-CREATE TABLE
- Photo - You show me first
- Russian Beauties
- SARDARJI CARTOONS
- spider man
- Thrisha Bath
- vb for beginner
- vb.net notes for my personal use
- xml basics
- XSS
Thank you spending your time here.
If possible you; can leave some comments or suggestions. Thanks a lot once again. |
||
| ||
Disclaimer and Copy Right |