ONLINE NESCAFE OF COLLEGE CAMPUS-14
(FORM OF DELETING PRODUCTS FROM DATABASE)
DELETE.ASP
This page shows you the how the form is created for deleting any item to the database PRODUCTS.
<html>
<body>
<form method=”post” action=”Delete_item.asp”>
<table align=”center” cellpadding=”0″ cellspacing=”0″ border=”0″>
<tr>
<td>Item Name:</td>
<td><input value=”"></td>
<td><sub><font face=”Arial, Helvetica, sans-serif” color=”#FF0000″ size=”-1″>*Enter the name in UPPERCASE</font></sub></td>
</tr>
<tr>
<td align=”center” colspan=”2″><input value=”Delete”></td>
</tr>
</table>
</body>
</html>
(ASP SCRIPT OF DELETING PRODUCTS FROM DATABASE)
DELETE ITEM.ASP
As you can see in DELETE.ASP that the values of the form have been sent to DELETE ITEM.asp. In this script, the connectivity is done with the database, validations are performed and product is deleted from it with the help of delete method.
If every validation is successful, then the following window will appear and database will be updated
<%@Language=”VBScript”%>
<%Option Explicit%>
<!–#include virtual=”/adovbs.inc”–>
<html>
<body>
<center>
<%
Dim MPath
MPath=Server.MapPath(“Storage.mdb”)
Dim objConn
Set objConn=Server.CreateObject(“ADODB.Connection”)
objConn.Mode=adModeReadWrite
objConn.Provider=”Microsoft.Jet.OLEDB.4.0″
objConn.Open (MPath)
Dim P_name
P_name=Request.Form(“P_name”)
If P_Name=”" Then
Response.Write “<br><br><br><font color=’#FF0000′ face=’Verdana, Arial, Helvetica, sans-serif’ size=’+3′>You can not leave the field blank.<br><br><br>”
Response.Write “<a href=’Delete.asp’>Back</a></font>”
Else
Dim strSQL
strSQL=”SELECT * FROM Products”
Dim objRS
Set objRS=Server.CreateObject( “ADODB.Recordset”)
objRS.Open strSQL,objConn,adOpenDynamic,adLockOptimistic
Dim Count
Count=0
Do While Not objRS.EOF
If objRS(“P_name”)=P_name Then
Count=Count+1
End If
objRS.MoveNext
Loop
objRS.Close
Set objRS=Nothing
If Count=0 Then
Response.Write “<br><br><br><font color=’#FF0000′ face=’Verdana, Arial, Helvetica, sans-serif’ size=’+3′>Product with such NAME is not present.<br><br><br>”
Response.Write “<a href=’Delete.asp’>Back</a></font>”
Else
strSQL=”SELECT * FROM Products WHERE P_name=’” & P_name & “‘ ”
Set objRS=Server.CreateObject( “ADODB.Recordset”)
objRS.Open strSQL,objConn,adOpenDynamic,adLockOptimistic
objRS.Delete
Response.Write “<br><br><br><font color=’#FF0000′ face=’Verdana, Arial, Helvetica, sans-serif’ size=’+3′>Item sucessfully deleted from the database.<br><br><br>”
Response.Write “<a href=’Delete.asp’>Back</a></font>”
objRS.Close
Set objRS=Nothing
objConn.Close
Set objConn=Nothing
End If
End If
%>
</center>
</body>
</html>
Now, the database will look as follows: