Internet Systems Design:
Technologies for Modern Information Systems

Database Manipulation

Example 1

HTML page to INSERT record to database

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
 

<title>Candy</title>
</head>

<body>
<form name=frmAddCandy action="addCandy.asp" method=post>

<p>Candy: <input type="text" name="txtCandy" size="20"> Price:
$<input type="text" name="txtPrice" size="20"></p>

<p><input type="submit" value="Add Candy" name="butAdd">&nbsp;
<input type="reset" value="Clear Form" name="butCancel" size="20"></p>
<p><a href='DeleteCandy.htm'>Delete Candy</a></p>
</form>
</body>

</html>

ASP Page to INSERT record to database


<%@ LANGUAGE='VBSCRIPT'%>
<html>

<head>

</head>

<body>
<%
'strSql will be the variable used to hold the sql statement string
dim strSql
Set MyConn = Server.CreateObject("ADODB.Connection")

MyConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Candy.mdb")

'grab the values from the form
candy = Request.form("txtCandy")
price = Request.Form("txtPrice")

'create the SQL statement that will insert the data to the table
'remember text values need single quotes wrapped around them
strSql = "INSERT INTO Products (Candy, Price) SELECT '" & candy & "'," & price
MyConn.Execute strSql
Response.Write "Added the candy with the sql statement: " & strSql
Set MyConn = nothing

%>
<p>
<a href='addCandy.htm'>Add Candy</a> - <a href='updateCandy.htm'>Update Candy</a> - <a href='deleteCandy.htm'>Delete Candy</a>
</p>
</body>

</html>
 

Example 2

HTML page to DELETE record from database

<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Candy</title>
</head>

<body>
<form name=frmDeleteCandy action="deleteCandy.asp" method=post>

<p>Candy: <input type="text" name="txtCandy" size="20"> </p>

<p><input type="submit" value="Delete Candy" name="butDelete">&nbsp;
<input type="reset" value="Clear Form" name="butCancel" size="20"></p>
<p><a href='addCandy.htm'>Add Candy</a></p>
</form>
</body>

</html>

 ASP Page to DELETE record from database

<%@ LANGUAGE='VBSCRIPT'%>
<html>

<head>

</head>

<body>
<%
'strSql will be the variable used to hold the sql statement string
dim strSql
Set MyConn = Server.CreateObject("ADODB.Connection")

MyConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Candy.mdb")

'grab the candy name from the form
candy = Request.form("txtCandy")

'create the SQL statement that will insert the data to the table
'remember text values need single quotes to wrapped around them
strSql = "Delete FROM Products Where Candy = '" & candy & "'"
MyConn.Execute strSql
Response.Write "Deleted the candy with the sql statement: " & strSql
Set MyConn = nothing

%>
<p>
<a href='addCandy.htm'>Add Candy</a> - <a href='updateCandy.htm'>Update Candy</a> - <a href='deleteCandy.htm'>Delete Candy</a>
</p>
</body>

</html>
 

Example 3

HTML page to UPDATE existing record in database

        <html>

        <head>
        <meta name="GENERATOR" content="Microsoft FrontPage 5.0">
        <meta name="ProgId" content="FrontPage.Editor.Document">
        <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
        <title>Candy</title>
        </head>

        <body>
        <form method="Post" action="updateCandy.asp">

    
<p> <select name = "selCandy" method ="post" size ="1">
        <option selected value="Gum">Gum</option>
        <option selected value="Suckers">Suckers</option>
        <option selected value="Taffy">Taffy</option>
        <option selected value="Skittles">Skittles</option>
        <option selected value="M&Ms">M&Ms</option>
        <option selected value="Lifesavers">Lifesavers</option>
        <option selected value="Snickers">Snickers</option>
        </select> New Price:<Input type='text' name='txtPrice' size=10>
        <input type="submit" value="Update Price">
        </p>
        </form>

     
</body>

        </html>

ASP Page to UPDATE existing record in database

<%@ LANGUAGE='VBSCRIPT'%>
<html>

<head>

</head>

<body>
<%
'strSql will be the variable used to hold the sql statement string
dim strSql
Set MyConn = Server.CreateObject("ADODB.Connection")

MyConn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Candy.mdb")

'grab the candy name from the form

candy = Request.form("selCandy")
price = Request.form("txtPrice")

'create the SQL statement that will insert the data to the table
'remember text values need single quotes to wrapped around them
strSql = "UPDATE Products SET Price = " & price & " WHERE Candy = '" & candy & "'"
MyConn.Execute strSql
Response.Write "Update the candy price with the sql statement: " & strSql
Set MyConn = nothing

%>
<p>
<a href='addCandy.htm'>Add Candy</a> - <a href='updateCandy.htm'>Update Candy</a> - <a href='deleteCandy.htm'>Delete Candy</a>
</p>
</body>

</html>