Forums
This topic is locked
Append data to existing record (field)
Posted 18 Jun 2007 17:56:21
1
has voted
18 Jun 2007 17:56:21 chris Rees posted:
Hello All,Hopefully some of the Dreamweaver CS3 and MSSQL gurus can help me out here.. <img src=../images/dmxzone/forum/icon_smile.gif border=0 align=middle>
I'm using IIS 6.0, MSSQL 2000, ASP and Dreamweaver CS3
I have a site that I'm using to track inventory. The site allows users to enter inventory, view the details, delete and update specs on the inventory.
I have an add inventory page where they're allowed to enter all the specs on a piece of inventory. There is also a hidden "history" which adds the data and "server added to the database" to the history field.
When I click on the page to show all, it lists out the servers, and hyperlinks the name to a details page which shows all the details of that server. It also has two other links, edit and delete (again both hyperlinked by the "ID" column).
When I click on the edit page, I want it show all the server details as editable fields, however I want to show history as a read only field, and whatever changes on that page (i.e. status changes from available to deployed, or amount of memory, ram, etc, is updated) I want those things to update and also write to the history field, time stamping and stating what changed.
I don't know how to update the record and append to what's already there. Dreamweaver CS3 writes everything differently than what I'm used to. Here's the code from the existing page update page:
<pre id=code><font face=courier size=2 id=code>
<%@LANGUAGE="VBSCRIPT"%>
<!--#include file="Connections/srvInventory.asp" -->
<%
Dim MM_editAction
MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME")
If (Request.QueryString <> "" Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If
' boolean to abort record edit
Dim MM_abortEdit
MM_abortEdit = false
%>
<%
' IIf implementation
Function MM_IIf(condition, ifTrue, ifFalse)
If condition = "" Then
MM_IIf = ifFalse
Else
MM_IIf = ifTrue
End If
End Function
%>
<%
If (CStr(Request("MM_update") = "form1" Then
If (Not MM_abortEdit) Then
' execute the update
Dim MM_editCmd
Set MM_editCmd = Server.CreateObject ("ADODB.Command"
MM_editCmd.ActiveConnection = MM_srvInventory_STRING
MM_editCmd.CommandText = "UPDATE dbo.srvInventory SET status = ?, redeploy_reason = ?, serial = ?, server_name = ?, model = ?, cpu = ?, cpu_speed = ?, ram = ?, disk_type = ?, disk_total_num = ?, disk_size = ?, power_sup_num = ?, store_only = ?, history = ? WHERE id = ?"
MM_editCmd.Prepared = true
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param1", 201, 1, 10, Request.Form("status") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param2", 201, 1, 75, Request.Form("reason") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param3", 201, 1, 30, Request.Form("serial") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param4", 201, 1, 30, Request.Form("server_name") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 201, 1, 30, Request.Form("model") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param6", 201, 1, 5, Request.Form("cpu") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param7", 201, 1, 10, Request.Form("cpu_speed") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param8", 201, 1, 10, Request.Form("ram") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param9", 201, 1, 10, Request.Form("disk_type") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param10", 201, 1, 10, Request.Form("disk_total_num") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param11", 201, 1, 10, Request.Form("disk_size") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param12", 201, 1, 10, Request.Form("power_sup_num") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param13", 201, 1, 10, MM_IIF(Request.Form("store_only", "Y", "N") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param14", 201, 1, -1, Request.Form("history") ' adLongVarChar
MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param15", 5, 1, -1, MM_IIF(Request.Form("MM_recordId", Request.Form("MM_recordId", null)) ' adDouble
MM_editCmd.Execute
MM_editCmd.ActiveConnection.Close
' append the query string to the redirect URL
Dim MM_editRedirectUrl
MM_editRedirectUrl = "srv_showall.asp"
If (Request.QueryString <> "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0) Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If
Response.Redirect(MM_editRedirectUrl)
End If
End If
%>
<%
Dim srvInventory__MMColParam
srvInventory__MMColParam = "1"
If (Request.QueryString("recordID" <> "" Then
srvInventory__MMColParam = Request.QueryString("recordID"
End If
%>
<%
Dim srvInventory
Dim srvInventory_cmd
Dim srvInventory_numRows
Set srvInventory_cmd = Server.CreateObject ("ADODB.Command"
srvInventory_cmd.ActiveConnection = MM_srvInventory_STRING
srvInventory_cmd.CommandText = "SELECT * FROM dbo.srvInventory WHERE id = ?"
srvInventory_cmd.Prepared = true
srvInventory_cmd.Parameters.Append srvInventory_cmd.CreateParameter("param1", 5, 1, -1, srvInventory__MMColParam) ' adDouble
Set srvInventory = srvInventory_cmd.Execute
srvInventory_numRows = 0
%>
<%
Dim srvModels
Dim srvModels_cmd
Dim srvModels_numRows
Set srvModels_cmd = Server.CreateObject ("ADODB.Command"
srvModels_cmd.ActiveConnection = MM_srvInventory_STRING
srvModels_cmd.CommandText = "SELECT * FROM dbo.srvModels"
srvModels_cmd.Prepared = true
Set srvModels = srvModels_cmd.Execute
srvModels_numRows = 0
%>
<%
Dim srvReason
Dim srvReason_cmd
Dim srvReason_numRows
Set srvReason_cmd = Server.CreateObject ("ADODB.Command"
srvReason_cmd.ActiveConnection = MM_srvInventory_STRING
srvReason_cmd.CommandText = "SELECT * FROM dbo.srvDeployReason"
srvReason_cmd.Prepared = true
Set srvReason = srvReason_cmd.Execute
srvReason_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Server Inventory</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="default.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.style4 {
color: #000099;
font-weight: bold;
}
-->
</style>
</head>
<body>
<div id="header">
<div id="logo">
<h1> </h1>
<h2> </h2>
</div>
<p> </p>
<div id="main_menu">
<div id="menu">
<ul>
<li class="active"><a href="index.asp" title="Home">Home</a></li>
<li><a href="add_srv.asp" title="Add a Server to the Database">Add Server</a></li>
<li><a href="srv_showall.asp" title="Show all Servers in the Database">Show All</a></li>
<li><a href="faq.asp" title="Frequently Asked Questions">FAQ</a></li>
<li><a href="#" title="E-mail the Server Inventory Site Webmaster">Contact Us</a></li>
</ul>
</div>
</div>
</div>
<div id="content">
<div id="leftcolumn">
<ul class="leftside">
<li class="leader"><strong>User Actions</strong></li>
<li><a href="add_srv.asp">Add Server</a></li>
<li><a href="redep_srv.asp">Redeploy Server</a></li>
<li><a href="srv_showall.asp">Show all Servers</a></li>
<li><a href="srv_showAvailable.asp">Show all Available</a></li>
<li><a href="srv_showRedeployed.asp">Show all Redeployed</a></li>
<li><a href="faq.asp">FAQ</a></li>
<li><a href="contactus.asp">Contact Us</a></li>
</ul>
<br />
</div>
<div id="rightcolumn">
<ul class="rightside">
<li class="leader"><strong>Admin Actions</strong></li>
<li><a href="srv_addmodels.asp">Manage Models</a></li>
<li><a href="db_deployReason.asp"> Redeploy Reasons</a></li>
</ul>
</div>
<div id="main">
<div id="welcome" class="post">
<h2 class="title">Server Inventory</h2>
<h3 class="date"><%= FormatDateTime(Now(), 1) %></h3>
<div class="story">
<form ACTION="<%=MM_editAction%>" name="form1" METHOD="POST" id="form1">
<table>
<tr valign="baseline">
<td align="right"><span class="style4">Status:</span></td>
<td><select name="status" style="width:120px;">
<option value="Available" <%If (Not isNull((srvInventory.Fields.Item("status".Value))) Then If ("Available" = CStr((srvInventory.Fields.Item("status".Value))) Then Response.Write("selected=""selected""" : Response.Write(""%>>Available</option>
<option value="Redeployed" <%If (Not isNull((srvInventory.Fields.Item("status".Value))) Then If ("Redeployed" = CStr((srvInventory.Fields.Item("status".Value))) Then Response.Write("selected=""selected""" : Response.Write(""%>>Redeployed</option>
</select> </td>
</tr>
<tr valign="baseline">
<td align="right"><span class="style4">Reason:</span></td>
<td><select name="reason" style="width:120px;">
<%
While (NOT srvReason.EOF)
%><option value="<%=(srvReason.Fields.Item("redeploy_reason".Value)%>" <%If (Not isNull((srvInventory.Fields.Item("redeploy_reason".Value))) Then If (CStr(srvReason.Fields.Item("redeploy_reason".Value) = CStr((srvInventory.Fields.Item("redeploy_reason".Value))) Then Response.Write("selected=""selected""" : Response.Write(""%> ><%=(srvReason.Fields.Item("redeploy_reason".Value)%></option>
<%
srvReason.MoveNext()
Wend
If (srvReason.CursorType > 0) Then
srvReason.MoveFirst
Else
srvReason.Requery
End If
%>
</select></td>
</tr>
<tr valign="baseline">
<td align="right"><span class="style4">Serial:</span></td>
<td><input name="serial" type="text" value="<%=(srvInventory.Fields.Item("serial".Value)%>" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="right"><span class="style4">Server Name:</span></td>
<td><input name="server_name" type="text" value="<%=(srvInventory.Fields.Item("server_name".Value)%>" size="32" /> </td>
</tr>
<tr valign="baseline">
<td align="right"><span class="style4">Model:</span></td>
<td><select name="model" style="width:120px;">
<%
While (NOT srvModels.EOF)
%>
<option value="<%=(srvModels.Fields.Item("srv_models".Value)%>"><%=(srvModels.Fields.Item("srv_models".Value)%></option>
<%
srvModels.MoveNext()
Wend
If (srvModels.CursorType > 0) Then
srvModels.MoveFirst
Else
srvModels.Requery
End If
%>
</select></td>
</tr>
<tr valign="baseline">
<td align="right"><span class="style4">Cpu:</span></td>
<td><input name="cpu" type="text" value="<%=(srvInventory.Fields.Item("cpu".Value)%>" size="32" /></td>
</tr>
<tr valign="baseline">
<td align="right"><span class="style4">CPU Speed:</span></td>
<td><input name="cpu_speed" type="text" value="<%=(srvInventory.Fields.Item("cpu_speed".Value)%>" size="32" /> </td>
</tr>
<tr valign="baseline">
<td align="right"><span class="style4">RAM:</span></td>
<td><input name="ram" type="text" value="<%=(srvInventory.Fields.Item("ram".Value)%>" size="32" /> </td>
</tr>
<tr valign="baseline">
<td align="right"><span class="style4">Disk Type:</span></td>
<td><input name="disk_type" type="text" value="<%=(srvInventory.Fields.Item("disk_type".Value)%>" size="32" /> </td>
</tr>
<tr valign="baseline">
<td align="right"><span class="style4"># Disks:</span></td>
<td><input name="disk_total_num" type="text" value="<%=(srvInventory.Fields.Item("disk_total_num".Value)%>" size="32" /> </td>
</tr>
<tr valign="baseline">
<td align="right"><span class="style4">Disk Size:</span></td>
<td><input name="disk_size" type="text" value="<%=(srvInventory.Fields.Item("disk_size".Value)%>" size="32" /> </td>
</tr>
<tr valign="baseline">
<td align="right"><span class="style4"># Power Sup's:</span></td>
<td><input name="power_sup_num" type="text" value="<%=(srvInventory.Fields.Item("power_sup_num".Value)%>" size="32" /> </td>
</tr>
<tr valign="baseline">
<td align="right"><span class="style4">Store Only:</span></td>
<td><input name="store_only" type="checkbox" value="<%=(srvInventory.Fields.Item("store_only".Value)%>" /></td>
</tr>
<tr>
<td align="right" valign="top"><span class="style4">History:</span></td>
<td valign="baseline"><textarea name="history" cols="50" rows="5" readonly="readonly"><%=(srvInventory.Fields.Item("history".Value)%></textarea> </td>
</tr>
<tr valign="baseline">
<td align="right"> </td>
<td><input type="submit" value="Update record" /> </td>
</tr>
</table>
<input type="hidden" name="id" />
<input type="hidden" name="MM_update" value="form1" />
<input type="hidden" name="MM_recordId" value="<%= srvInventory.Fields.Item("id".Value %>" />
</form>
</div>
</div>
</div>
<div id="footer">
<p id="legal">All Rights Reserved. Designed by <a href="#">Contact Us</a></p>
<p id="links"><a href="#">Privacy Policy</a> | <a href="#">Terms of Use</a></p>
</div>
</body>
</html>
<%
srvInventory.Close()
Set srvInventory = Nothing
%>
<%
srvModels.Close()
Set srvModels = Nothing
%>
<%
srvReason.Close()
Set srvReason = Nothing
%>
</font id=code></pre id=code>