ONLINE NESCAFE OF COLLEGE CAMPUS-13
(FORM OF ADDING PRODUCTS TO DATABASE)
ADD.ASP
This page shows you the how the form is created for adding any item to the database PRODUCTS.
<html>
<body>
<form method=”post” action=”Add_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>Item Price:</td>
<td><input value=”"></td>
</tr>
<tr>
<td>Item Quantity:</td>
<td><input value=”"></td>
</tr>
<tr>
<td>Image Name:</td>
<td><input value=”"></td>
</tr>
<tr>
<td>Type</td>
<td><Select>
<option>MAGGI</option>
<option>COLD</option>
<option>HOT</option>
<option>OTHER</option>
</Select>
</td>
</tr>
<tr>
<td align=”center” colspan=”2″><input value=”Add”></td>
</tr>
</table>
</form>
</body>
</html>
(ASP SCRIPT OF ADDING PRODUCTS TO DATABASE)
ADD ITEM.ASP
As you can see in ADD.ASP that the values of the form have been sent to ADD ITEM.asp. In this script, the connectivity is done with the database, validations are performed and new product is added to it with the help of ADDNEW method.
If every validation is successful, then the following window will appear and database will be updated.
<%@LANGUAGE=”VBSCRIPT”%>
<!–#include virtual=”/adovbs.inc”–>
<html>
<body>
<center>
<%
Dim P_Name
Dim P_Price
Dim P_Image
Dim P_Quntity
Dim P_type
P_Name=Request.Form(“P_Name”)
P_Price=Request.Form(“P_Price”)
P_Quantity=Request.Form(“P_Quantity”)
P_Image=Request.Form(“P_Image”)
P_type=Request.Form(“P_type”)
If P_Name=”" OR P_Price=”" OR P_Quantity=”" OR P_Image=”" Then
Response.Write “<br><br><br><font color=’#FF0000′ face=’Verdana, Arial, Helvetica, sans-serif’ size=’+3′>You can not leave any field blank.<br><br><br>”
Response.Write “<a href=’Add.asp’>Back</a></font>”
Else
Dim objConn,objRS,MPath
MPath=Server.MapPath(“Storage.mdb”)
Set objConn=Server.CreateObject(“ADODB.Connection”)
objConn.Provider=”Microsoft.Jet.OLEDB.4.0″
objConn.Open (MPath)
Dim strSQL
strSQL=”SELECT * FROM Products WHERE P_Name=’” & P_Name & “‘”
Set objRS=Server.CreateObject( “ADODB.Recordset”)
objRS.Open strSQL,objConn,adOpenDynamic,adLockOptimistic
Dim Count
Count=0
Do While Not objRS.EOF
Count=Count+1
objRS.MoveNext
Loop
If Count<>0 Then
Response.Write “<br><br><br><font color=’#FF0000′ face=’Verdana, Arial, Helvetica, sans-serif’ size=’+3′>Product with the given name is already present.<br><br><br>”
Response.Write “<a href=’Add.asp’>Back</a></font>”
objRS.Close
Set objRS=Nothing
objConn.Close
Set objConn=Nothing
Else
If IsNumeric(P_Price)=False OR IsNumeric(P_Quntity)=False Then
Response.Write “<br><br><br><font color=’#FF0000′ face=’Verdana, Arial, Helvetica, sans-serif’ size=’+3′>Product and Price must have only numeric values.<br><br><br>”
Response.Write “<a href=’Add.asp’>Back</a></font>”
Else
objRS.AddNew
objRS(“P_Name”)=P_Name
objRS(“P_Price”)=P_Price
objRS(“P_Quantity”)=P_Quantity
objRS(“P_Image”)=P_Image
objRS(“P_type”)=P_type
objRS.Update
objRS.Close
Set objRS=Nothing
objConn.Close
Set objConn=Nothing
Response.Write “<br><br><br><font color=’#FF0000′ face=’Verdana, Arial, Helvetica, sans-serif’ size=’+3′>Item sucessfully added to the database.<br><br><br>”
Response.Write “<a href=’Add.asp’>Back</a></font>”
End If
End If
End If
%>
</center>
</body>
</html>
Now, the database will look as follows: