Link to home
Start Free TrialLog in
Avatar of keeper3
keeper3

asked on

Removing 1 of 2 url parameters after inserting a record

Situation is, I have a detail page (vendor_detail.asp) for a particular vendor, displaying all of his equipment.  This page has an existing url parameter for the vendor's specific id (vendor_id) so that only his equipment is displayed.  You can click on each piece of equipment to go and edit the details of that equipment (equip_edit.asp).  Currently, when you click on the equipment piece, it will create a new url parameter(equip_id) so that the edit page only displays that piece of equipement for editing.  Additionally, I am passing the existing url parameter of vendor_id so that I can pass it back after submitting the edit equipment (and return to the same vendor_detail.asp page).

My problem is that after submitting the updated equipment record, it is passing back both url parameters (vendor_id and equip_id).  This is a problem if I want to edit the equipment detail again as it will now have 3 url parameters (vendor_id and 2 equip_id's), and errors out the page, message included for giggles.

ADODB.Recordset.1 error '80004005'

SQLState: 42000
Native Error Code: 1064
[TCX][MyODBC]You have an error in your SQL syntax near ' 2' at line 1

I am using the built in functionality of Dreamweaver for "Go to Detail Page".

I guess my question has a couple parts:

a) I don't remember specifying in the first place that the equip_edit.asp should pass url parameters back after submitting the update record.  Is this a default when using the "update record" behavior?

b) How can you selectively pass back url parameters?  I don't see this as built in to dreamweaver.  The only url parameter I want to pass back is the vendor_id one.

I have relatively meager hand coding skills, though I can certainly follow directions like a champ.

Any help here would be appreciated.

Thanks
Avatar of zombeen
zombeen

Can u post the code here for us to have a look. It might have to be handled at the background using some ASP skills.

Zombeen
ASKER CERTIFIED SOLUTION
Avatar of welcht
welcht

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of keeper3

ASKER

Code is below, apologies for the delay...  I tried to cut out the stuff that was irrelevant, but there still a good  bit.  For reference, there are two url parameters that are getting passed to this asp page, "vendor_id" and "resis_id".  After I do the submit to delete the record (or edit, I have the same issue with both), both parameters are getting bassed back to the redirect page after the submission.  I would only like to pass back one, the "vendor_id" parameter.  Thanks for any help, John.

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<%
// *** Edit Operations: declare variables

// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
if (Request.QueryString) {
  MM_editAction += "?" + Request.QueryString;
}

// boolean to abort record edit
var MM_abortEdit = false;

// query string to execute
var MM_editQuery = "";
%>
<%
// *** Delete Record: declare variables

if (String(Request("MM_delete")) == "form1" &&
    String(Request("MM_recordId")) != "undefined") {

  var MM_editConnection = MM_hosted_auburn_STRING;
  var MM_editTable = "resis_data";
  var MM_editColumn = "resis_id";
  var MM_recordId = "" + Request.Form("MM_recordId") + "";
  var MM_editRedirectUrl = "resis_list.asp";

  // append the query string to the redirect URL
  if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.Count > 0) {
    MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1)?"?":"&") + Request.QueryString;
  }
}
%>
<%
// *** Delete Record: construct a sql delete statement and execute it

if (String(Request("MM_delete")) != "undefined" &&
    String(Request("MM_recordId")) != "undefined") {

  // create the sql delete statement
  MM_editQuery = "delete from " + MM_editTable + " where " + MM_editColumn + " = " + MM_recordId;

  if (!MM_abortEdit) {
    // execute the delete
    var MM_editCmd = Server.CreateObject('ADODB.Command');
    MM_editCmd.ActiveConnection = MM_editConnection;
    MM_editCmd.CommandText = MM_editQuery;
    MM_editCmd.Execute();
    MM_editCmd.ActiveConnection.Close();

    if (MM_editRedirectUrl) {
      Response.Redirect(MM_editRedirectUrl);
    }
  }

}
%>
<%
var vendor_rec__MMColParam = "1";
if (String(Request.QueryString("vendor_id")) != "undefined" && 
    String(Request.QueryString("vendor_id")) != "") {
  vendor_rec__MMColParam = String(Request.QueryString("vendor_id"));
}
%>
<%
var vendor_rec = Server.CreateObject("ADODB.Recordset");
vendor_rec.ActiveConnection = MM_hosted_auburn_STRING;
vendor_rec.Source = "SELECT vendor_id, vendor_name FROM vendor_data WHERE vendor_id = "+ vendor_rec__MMColParam.replace(/'/g, "''") + "";
vendor_rec.CursorType = 0;
vendor_rec.CursorLocation = 2;
vendor_rec.LockType = 1;
vendor_rec.Open();
var vendor_rec_numRows = 0;
%>
<%
var resis_rec__MMColParam = "1";
if (String(Request.QueryString("resis_id")) != "undefined" && 
    String(Request.QueryString("resis_id")) != "") {
  resis_rec__MMColParam = String(Request.QueryString("resis_id"));
}
%>
<%
var resis_rec = Server.CreateObject("ADODB.Recordset");
resis_rec.ActiveConnection = MM_hosted_auburn_STRING;
resis_rec.Source = "SELECT r.*,r.watts*r.qty*r.h_w/1000*4.33*ec.kwh_cost as resis_op  FROM resis_data r,elec_cost ec  WHERE resis_id = "+ resis_rec__MMColParam.replace(/'/g, "''") + "";
resis_rec.CursorType = 0;
resis_rec.CursorLocation = 2;
resis_rec.LockType = 1;
resis_rec.Open();
var resis_rec_numRows = 0;
%>
<% var MM_paramName = ""; %>
<%
// *** Go To Record and Move To Record: create strings for maintaining URL and Form parameters

// create the list of parameters which should not be maintained
var MM_removeList = "&index=";
if (MM_paramName != "") MM_removeList += "&" + MM_paramName.toLowerCase() + "=";
var MM_keepURL="",MM_keepForm="",MM_keepBoth="",MM_keepNone="";

// add the URL parameters to the MM_keepURL string
for (var items=new Enumerator(Request.QueryString); !items.atEnd(); items.moveNext()) {
  var nextItem = "&" + items.item().toLowerCase() + "=";
  if (MM_removeList.indexOf(nextItem) == -1) {
    MM_keepURL += "&" + items.item() + "=" + Server.URLencode(Request.QueryString(items.item()));
  }
}

// add the Form variables to the MM_keepForm string
for (var items=new Enumerator(Request.Form); !items.atEnd(); items.moveNext()) {
  var nextItem = "&" + items.item().toLowerCase() + "=";
  if (MM_removeList.indexOf(nextItem) == -1) {
    MM_keepForm += "&" + items.item() + "=" + Server.URLencode(Request.Form(items.item()));
  }
}

// create the Form + URL string and remove the intial '&' from each of the strings
MM_keepBoth = MM_keepURL + MM_keepForm;
if (MM_keepBoth.length > 0) MM_keepBoth = MM_keepBoth.substring(1);
if (MM_keepURL.length > 0)  MM_keepURL = MM_keepURL.substring(1);
if (MM_keepForm.length > 0) MM_keepForm = MM_keepForm.substring(1);
%>
<html>
<head>
<


  <p>
    <input name="Submit" type="submit" onClick="MM_validateForm('textfield2','','R','textfield3','','RisNum','textfield4','','RisNum','textfield5','','NisNum','textfield6','','RisNum');return document.MM_returnValue" value="Delete?">
    <a href="resis_list.asp?<%= MM_keepNone + ((MM_keepNone!="")?"&":"") + "vendor_id=" + resis_rec.Fields.Item("vendor_id").Value %>">Cancel
    and Return to Vendor Detail</a> </p>
  <p>&nbsp;</p>
  <p><IMG SRC="charts/resis_single.asp?<%= MM_keepURL %>">
  </p>
  <p> </p>
  <input type="hidden" name="MM_delete" value="form1">
  <input type="hidden" name="MM_recordId" value="<%= resis_rec.Fields.Item("resis_id").Value %>">
</form>
<p>&nbsp; </p>
</body>
</html>
<%
vendor_rec.Close();
%>
<%
resis_rec.Close();
%>


Avatar of keeper3

ASKER

One more thought.  What's wrong with the below code?  This should work, as I get the behavior I want (only one url parameter, vendor_id) when I setup a hyperlink this way, but I can't get the redirect url to use this.  Pardon my ignorance on this...  Thanks.

var MM_editRedirectUrl = "resis_list.asp" + <%= MM_keepNone + ((MM_keepNone!="")?"&":"") + "vendor_id=" + resis_rec.Fields.Item("vendor_id").Value %>;

I get a error of
Error Type:
Microsoft JScript compilation (0x800A03EA)
Syntax error

on the line.