How to make a website using ASP(TUTORIAL-15)

ONLINE NESCAFE OF COLLEGE CAMPUS-15

(FORM OF UPDATING PRODUCTS FROM DATABASE)

UPDATE.ASP

 

This page shows you the how the form is created for updating any item to the database PRODUCTS.

 update

<html>

<body>

<form method=”post” action=”update_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 align=”center” colspan=”2″><input value=”Update”></td>

</tr>

</table>

</form>

</body>

</html>

(ASP SCRIPT OF UPDATING PRODUCTS FROM DATABASE)

UPDATE ITEM.ASP

As you can see in UPDATE.ASP that the values of the form have been sent to UPDATE ITEM.asp. In this script, the connectivity is done with the database, validations are performed  and  product is UPDATED from it with the help of UPDATE method.  

If every validation is successful, then the following window will appear and database will be updated

 after update

<%@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

            Dim P_price

            Dim P_quantity

            Dim P_image

            P_name=Request.Form(“P_name”)

            P_price=Request.Form(“P_price”)

            P_quantity=Request.Form(“P_quantity”)

            P_image=Request.Form(“P_image”)

 

           

            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′>No field can be left blank.<br><br><br>”

                                    Response.Write “<a href=’update.asp’>Back</a></font>”

            Else

                        Dim strSQL

                        strSQL=”SELECT * FROM Products”

                       

                        Dim objRS

                        Set objRS=Server.CreateObject(“ADODB.Recordset”)

                        objRS.Open strSQL,objConn,,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′>No such item is present.<br><br><br>”

                                    Response.Write “<a href=’update.asp’>Back</a></font>”

                       

                        ElseIf IsNumeric(P_price)=False OR IsNumeric(P_quantity)=False Then

                        Response.Write “<br><br><br><font color=’#FF0000′ face=’Verdana, Arial, Helvetica, sans-serif’ size=’+3′>Price and quantity must have numeric values.<br><br><br>”

                                    Response.Write “<a href=’update.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(“p_price”)=P_price

                                                objRS(“P_quantity”)=P_quantity

                                                objRS(“P_image”)=P_image

                                                objRS.Update

                                                Response.Write “<br><br><br><font color=’#FF0000′ face=’Verdana, Arial, Helvetica, sans-serif’ size=’+3′>DATA hase been successfully changed.<br><br><br>”

                                    Response.Write “<a href=’update.asp’>Back</a></font>”

                                    End If

                        End If

                                   

                                   

                                   

                                   

                                    Set objRS=Nothing

                                    objConn.Close

                                    Set objConn=Nothing

           

           

           

           

%>

</center>

</body>

</html>

 

Now, the database will look as follows:

 data update

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>