Hi All,
Here is the code that solved my problem.
1. This code adds data from the form to the database.
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>
<body>
<%
Dim DB
Set DB = Server.CreateObject ("ADODB.Connection")
DB.Open "driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;pwd=;database=as setdb"
Dim RS
Set RS = Server.CreateObject ("ADODB.Recordset")
RS.Open "SELECT * FROM asset, branch, cost, location, type", DB
Dim asset_number, asset_description, type_name, asset_category, cost_bearer, asset_model, location_name, branch_name, vendor_name, asset_serial
Dim asset_purchase_date, quantity, purchase_price, taxvalue, asset_insured_value, asset_scrap_value
asset_number = Request.Form("txtassetnumber")
location_name = Request.Form("txtlocation")
asset_description = Request.Form("txtdescription")
type_name= Request.Form("txttype")
asset_category = Request.Form("txtcategory")
cost_bearer = Request.Form("txtcostcenter")
asset_model = Request.Form("txtmodel")
branch_name = Request.Form("txtbranch")
vendor_name = Request.Form("txtvendor")
asset_serial = Request.Form("txtserial")
asset_purchase_date = Request.Form("txtpurchasedate")
quantity = Request.Form("txtquantity")
purchase_price = Request.Form("txtpurchaseprice")
asset_tax_value = Request.Form("txttaxvalue")
asset_insured_value = Request.Form("txtinsuredvalue")
asset_scrap_value = Request.Form("txtscrapvalue")
Dim sqlasset
sqlasset="INSERT INTO asset (asset_number, asset_description, asset_model, asset_serial, asset_purchase_date, asset_tax_value, asset_insured_value, asset_scrap_value) VALUES('"&asset_number&"','"&asset_description&"', '"&asset_model&"','"&asset_serial&"','"&asset_purc hase_date&"','"&asset_tax_value&"','"&asset_insure d_value&"','"&asset_scrap_value&"')"
DB.Execute(sqlasset)
Dim sqltype
sqltype="INSERT INTO type (type_name, quantity) VALUES('"&type_name&"','"&quantity&"')"
DB.Execute(sqltype)
Dim sqllocation
sqllocation="INSERT INTO location(location_name) VALUES('"&location_name&"')"
DB.Execute(sqllocation)
Dim sqlvendor
sqlvendor="INSERT INTO vendor (vendor_name) VALUES('"&vendor_name&"')"
DB.Execute(sqlvendor)
Dim sqlbranch
sqlbranch="INSERT INTO branch (branch_name) VALUES('"&branch_name&"')"
DB.Execute(sqlbranch)
Dim sqlcost
sqlcost="INSERT INTO cost (cost_bearer, purchase_price) VALUES('"&cost_bearer&"','"&purchase_price&"')"
DB.Execute(sqlcost)
On Error Resume Next
If RS.EOF And RS.BOF Then
End If
RS.Close
DB.Close
Response.Redirect("http://localhost/home.html")
%>
</body>
</html>
2. This code retrieves data from the database into text fields on a form.
<%
Dim DB
Set DB = Server.CreateObject ("ADODB.Connection")
DB.Mode = adModeReadWrite
DB.Open "driver={MySQL ODBC 3.51 Driver};server=localhost;uid=root;pwd=;database=as setdb"
Dim RS
Set RS = Server.CreateObject ("ADODB.Recordset")
RS.Open "SELECT * FROM asset, branch, location, type, cost", DB
%>
<%
If RS.EOF And RS.BOF Then
Response.Write "There are 0 records."
End If
%>
<Script>
</Script>
<form name="form1" method="post" action="modify_asset.asp">
<table width="763" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="129"><span class="style1">Asset No</span>: </td>
<td width="244"><input type="text" name="txtassetnumber" value="<%=Server.HTMLEncode(RS.Fields("asset_numbe r").Value)%>" ></td>
<td width="109" class="style1">Location:</td>
<td width="224"><select name="txtlocation" value="<%=Server.HTMLEncode(RS.Fields("location_na me").Value)%>" >
<option>Administration (ADM)</option>
<option>Banking Hall (BH)</option>
<option>Data Center (DC)</option>
<option>Networking (NWK)</option>
<option>Retail/Commercial Banking (RCB)</option>
<option>Domestic Operations (DOPS)</option>
<option>Treasury (TRY)</option>
<option>E-Business (EB)</option>
<option>Strategy (STR)</option>
<option>Corporate Banking (CB)</option>
<option>Corporate Services ( CS)</option>
<option>Executive Lunge (EL)</option>
<option>Internal Control (IC)</option>
<option>Financial Control (FC)</option>
</select></td>
</tr>
<tr>
<td><span class="style1">Description:</span></td>
<td><input type="text" textarea name="txtdescription" value="<%=Server.HTMLEncode(RS.Fields("asset_descr iption").Value)%>" /></textarea>
<td class="style1">Branch:</td>
<td><select name="txtbranch"value="<%=Server.HTMLEncode(RS.Fie lds("branch_name").Value)%>" >
<option>Head Office (001)</option>
<option>Kumasi (002)</option>
</select></td>
</tr>
<tr>
<td class="style1">Type:</td>
<td><select name="txttype" value="<%=Server.HTMLEncode(RS.Fields("type_name") .Value)%>" >
<option>Building (BUD)</option>
<option>Computer (COM)</option>
<option>Equipment (EQP)</option>
<option>Furniture & Fittings (FF)</option>
<option>Motor Vehicle (MV)</option>
<option>Plant & Machinery (PLM)</option>
<option>None</option>
</select></td>
<td class="style1">Category:</td>
<td><select name="txtcategory" value="<%=Server.HTMLEncode(RS.Fields("asset_categ ory").Value)%>" >
<option>Short Term (ST)</option>
<option>Long Term (LT)</option>
<option>None</option>
</select></td>
</tr>
<tr>
<td class="style1">Cost Center: </td>
<td><select name="txtcostcenter" value="<%=Server.HTMLEncode(RS.Fields("cost_bearer ").Value)%>" >
<option>Administration (ADM)</option>
<option>Marketing (MKT)</option>
<option selected>Operations (OPS)</option>
<option>Internal Control (IC)</option>
<option>Financial Control (FC)</option>
<option>Treasury (TRY)</option>
<option>Human Resource Mgt. (HR)</option>
<option>Technology Services (IT)</option>
</select></td>
<td class="style1">Serial No: </td>
<td><input type="text" name="txtserial" value="<%=Server.HTMLEncode(RS.Fields("asset_seria l").Value)%>"></td>
</tr>
<tr>
<td class="style1">Model:</td>
<td><input type="text" name="txtmodel" value="<%=Server.HTMLEncode(RS.Fields("asset_model ").Value)%>" ></td>
<td> </td>
<td> </td>
</tr>
</table>
<p> </p>
<table width="394" border="1" align="left" cellpadding="2" cellspacing="2">
<tr>
<td width="130">Purchase Date: </td>
<td width="222"><input name="txtpurchasedate" type="text" id="txtpurchasedate" value="<%=Server.HTMLEncode(RS.Fields("asset_purch ase_date").Value)%>"></td>
</tr>
<tr>
<td>Quantity:</td>
<td><input name="txtquantity" type="text" id="txtquantity" value="<%=Server.HTMLEncode(RS.Fields("quantity"). Value)%>"></td>
</tr>
<tr>
<td>Purchase Price: ¢</td>
<td><input name="txtpurchaseprice" type="text" id="txtpurchaseprice" value="<%=Server.HTMLEncode(RS.Fields("purchase_pr ice").Value)%>"></td>
</tr>
</table>
<table width="369" border="1" align="left" cellpadding="2" cellspacing="2">
<tr>
<td width="126">Tax Value: ¢</td>
<td width="178"><input name="txttaxvalue" type="text" id="txttaxvalue" value="<%=Server.HTMLEncode(RS.Fields("asset_tax_v alue").Value)%>"></td>
</tr>
<tr>
<td>Insured Value: ¢</td>
<td><input name="txtinsuredvalue" type="text" id="txtinsuredvalue" value="<%=Server.HTMLEncode(RS.Fields("asset_insur ed_value").Value)%>"></td>
</tr>
<tr>
<td>Scrap Value: ¢</td>
<td><input name="txtscrapvalue" type="text" id="txtscrapvalue" value="<%=Server.HTMLEncode(RS.Fields("asset_scrap _value").Value)%>"></td>
</tr>
</table>
<p> </p>
<p> </p>
<p> </p>
<p> </p>
<input type="submit" name="Submit" value="Update">
<input name="Next" type="submit" id="" value="Next">
</form>
<p> </p>
<p> </p>
</body>
</html>
|