Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 7th, 2004, 08:31 AM
Authorized User
 
Join Date: Nov 2004
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to don baroo Send a message via Yahoo to don baroo
Default

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 &amp; Fittings (FF)</option>
          <option>Motor Vehicle (MV)</option>
          <option>Plant &amp; 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>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
  </table>
  <p>&nbsp;</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: &cent;</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: &cent;</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: &cent;</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: &cent;</td>
      <td><input name="txtscrapvalue" type="text" id="txtscrapvalue" value="<%=Server.HTMLEncode(RS.Fields("asset_scrap _value").Value)%>"></td>
    </tr>
  </table>

  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <input type="submit" name="Submit" value="Update">
  <input name="Next" type="submit" id="" value="Next">
</form>
<p>&nbsp;</p>
<p>&nbsp;</p>
</body>
</html>






Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the error message for a 500 server error? chobo2 C# 2005 1 May 4th, 2008 03:11 AM
Where does the error message go? Wei Wang BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 1 March 13th, 2006 02:03 PM
Error Message alannoble26 Excel VBA 4 November 25th, 2005 11:20 AM
error message. Tasha Access VBA 2 August 11th, 2004 11:07 PM
Help with Error message mariakovacs Classic ASP Databases 3 October 10th, 2003 03:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.