
December 15th, 2003, 10:20 AM
|
|
Registered User
|
|
Join Date: Dec 2003
Posts: 3
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Command Text Too Long Error when Inserting a Record
I'm currently working on an ASP site that connects to a MySQL database (code for the page is below)
I've built a form that allows users to insert press releases. They add the date and title and then the text of the release.
The problem that I'm having is that every so often when the user submits the form they get an error message saying "Command text too long" The record isn't added to the database after this
I use a longtext field for holding the main text of the press release
Can anyone shed any light on this for me??
Cheers
Here's the code that I'm using on the page
(I'm using Dreameaver MX to build my pages)
Quote: <%@LANGUAGE="JAVASCRIPT" CODEPAGE="1252"%>
<!--#include file="../../Connections/connClubRedesign.asp" -->
<%
// *** Restrict Access To Page: Grant or deny access to this page
var MM_authorizedUsers="admin";
var MM_authFailedURL="../accessdenied.asp";
var MM_grantAccess=false;
if (String(Session("MM_Username")) != "undefined") {
if (false || (String(Session("MM_UserAuthorization"))=="") || (MM_authorizedUsers.indexOf(String(Session("MM_UserAuthorization"))) >=0)) {
MM_grantAccess = true;
}
}
if (!MM_grantAccess) {
var MM_qsChar = "?";
if (MM_authFailedURL.indexOf("?") >= 0) MM_qsChar = "&";
var MM_referrer = Request.ServerVariables("URL");
if (String(Request.QueryString()).length > 0) MM_referrer = MM_referrer + "?" + String(Request.QueryString());
MM_authFailedURL = MM_authFailedURL + MM_qsChar + "accessdenied=" + Server.URLEncode(MM_referrer);
Response.Redirect(MM_authFailedURL);
}
%>
<%
// *** 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 = "";
%>
<%
// *** Insert Record: set variables
if (String(Request("MM_insert")) == "form1") {
var MM_editConnection = MM_connClubRedesign_STRING;
var MM_editTable = "cukdb.pressrelease";
var MM_editRedirectUrl = "addpressrelease.asp";
var MM_fieldsStr = "date|value|title|value|text|value|image|value";
var MM_columnsStr = " date|',none,NULL|title|',none,''|text|',none,''|im
age|',none,''";
// create the MM_fields and MM_columns arrays
var MM_fields = MM_fieldsStr.split("|");
var MM_columns = MM_columnsStr.split("|");
// set the form values
for (var i=0; i+1 < MM_fields.length; i+=2) {
MM_fields[i+1] = String(Request.Form(MM_fields[i]));
}
// 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;
}
}
%>
<%
// *** Insert Record: construct a sql insert statement and execute it
if (String(Request("MM_insert")) != "undefined") {
// create the sql insert statement
var MM_tableValues = "", MM_dbValues = "";
for (var i=0; i+1 < MM_fields.length; i+=2) {
var formVal = MM_fields[i+1];
var MM_typesArray = MM_columns[i+1].split(",");
var delim = (MM_typesArray[0] != "none") ? MM_typesArray[0] : "";
var altVal = (MM_typesArray[1] != "none") ? MM_typesArray[1] : "";
var emptyVal = (MM_typesArray[2] != "none") ? MM_typesArray[2] : "";
if (formVal == "" || formVal == "undefined") {
formVal = emptyVal;
} else {
if (altVal != "") {
formVal = altVal;
} else if (delim == "'") { // escape quotes
formVal = "'" + formVal.replace(/'/g,"''") + "'";
} else {
formVal = delim + formVal + delim;
}
}
MM_tableValues += ((i != 0) ? "," : "") + MM_columns[i];
MM_dbValues += ((i != 0) ? "," : "") + formVal;
}
MM_editQuery = "insert into " + MM_editTable + " (" + MM_tableValues + ") values (" + MM_dbValues + ")";
if (!MM_abortEdit) {
// execute the insert
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);
}
}
}
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><HTML><!-- InstanceBegin template="/Templates/main.dwt.asp" codeOutsideHTMLIsLocked="false" --><HEAD>
<!-- InstanceBeginEditable name="doctitle" -->
<TITLE></TITLE>
<meta name="description" content="">
<meta name="keywords" content="">
<!-- InstanceEndEditable -->
<META http-equiv="Content-Type" content="text/html; charset=windows-1252">
<STYLE>all.clsMenuItemNS {
Z-INDEX: 100; FONT: bold .80em Verdana; CURSOR: hand; COLOR: white; TEXT-DECORATION: none
}
.clsMenuItemIE {
Z-INDEX: 100; FONT: bold .80em Verdana; CURSOR: hand; COLOR: white; TEXT-DECORATION: none
}
#MainTable A:hover {
COLOR: #facb00
}
.clsMenuItemDrop {
Z-INDEX: 100; FONT: bold .60em Verdana; CURSOR: hand; COLOR: white; TEXT-DECORATION: none
}
</STYLE>
<SCRIPT language=JavaScript>
var keepstatic=0 //specify whether menu should stay static 0=non static (works only in IE4+)
var menucolor="#003366" //specify menu color
var submenuwidth=130 //specify sub menus' color
</SCRIPT>
<link href="../../style/mac-ie.css" rel="stylesheet" type="text/css">
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</HEAD>
<BODY bgcolor="#003366" background="../../images/clubback.gif" text="#FFFFFF" link="facb00" vlink="facb00" alink="facb00" leftMargin=0 topMargin=0 marginwidth="0" marginheight="0">
<table width="760" border="0" align="left" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td height="19" colspan="3" valign="top"> <div align="left">
<script language="JavaScript" src="../../menucontext.js"></script>
<script language="JavaScript" src="../../menu.js"></script>
<noscript>
<span class="smalltext"> This site utilises a JavaScript menu bar. As
you do not have JavaScript enabled the main category links are provided
here: <br>
<a href="../../aboutus/index.asp">About Us</a> | <a href="../../tenders/index.asp">Tenders</a>
| <a href="../../events/index.asp">Events</a> | <a href="../../recruitment/index.asp">Recruitment</a>
| <a href="../../train-dev/index.asp">Training and Development</a> | <a href="../../news/index.asp">News</a>
| <a href="../../businessinsight/index.asp">Business Insight</a> | <a href="../../resourcelib/index.asp">Resource/Library</a>
| <a href="../../index.asp">Home</a></span>
</noscript>
<script language=JavaScript>
showToolbar();
</script>
<script language=JavaScript>
function UpdateIt(){
if (ie&&keepstatic&&!opr6)
document.all["MainTable"].style.top = document.body.scrollTop;
setTimeout("UpdateIt()", 200);
}
UpdateIt();
</script>
</div></td>
</tr>
<tr>
<td width="11" height="8"></td>
<td width="740"></td>
<td width="9"></td>
</tr>
<tr>
<td height="80"></td>
<td valign="top"> <div align="left"><img src="../../images/newtopbanner.jpg" alt="Banner Image" width="740" height="80" border="0" usemap="#Map">
</div></td>
<td></td>
</tr>
<tr>
<td height="18"></td>
<td></td>
<td></td>
</tr>
<tr>
<td height="172"></td>
<td valign="top"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<!--DWLayoutTable-->
<tr>
<td width="560" height="32" valign="top"><!-- InstanceBeginEditable name="maintext" -->
<p><!-- #BeginLibraryItem "/Library/back to categories.lbi" class="maintext" --><a href="../categories.asp"><span class="headings">Back to categories</span></a><!-- #EndLibraryItem --></p>
<p class="maintext">Use this form to add a Press Release</p>
<p class="maintext">Once you have submitted the informatio you will
be returned to this page so you can continue adding</p>
<p class="maintext">Once you have finished adding click <a href="../../news/pressreleases/index.asp">here</a>
to view what has been added </p>
<p><span class="maintext">To add a blank line enter <br><br></span></p>
<p><span class="maintext">If the press release has an image associated
with it then the image will need to be uploaded to /news/pressreleases/images/
- please make sure that the image is of a reasonable size i.e. 20k.
If there is no image associated with the press release then leave
the field as it is</span><br>
</p>
<form method="post" action="<%=MM_editAction%>" name="form1">
<table width="540" align="left">
<tr valign="top" class="maintext">
<td align="right" nowrap>Date:<br> <span class="smalltext"><strong>(Enter
as YYY-MM-DD <br>
e.g. 2003-08-29)</strong></span></td>
<td> <input type="text" name="date" value="" size="32"> </td>
</tr>
<tr valign="top" class="maintext">
<td align="right" nowrap>Title:</td>
<td> <input type="text" name="title" value="" size="32"> </td>
</tr>
<tr valign="top" class="maintext">
<td align="right" nowrap>Text:</td>
<td> <textarea name="text" cols="45" rows="15"></textarea>
</td>
</tr>
<tr valign="top" class="maintext">
<td align="right" nowrap>Image:</td>
<td> <input type="text" name="image" value="../news/pressreleases/images/shim.gif" size="75">
</td>
</tr>
<tr valign="top" class="maintext">
<td align="right" nowrap> </td>
<td> <input type="submit" value="Insert Record"> <input type="reset" name="Reset" value="Clear Form">
</td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
<!-- InstanceEndEditable --></td>
<td width="18" rowspan="2"> </td>
<td width="162" rowspan="2" valign="top" nowrap class="usefullinks">
<div align="center">
</a>
</div></td>
</tr>
<tr>
</tr>
</table></td>
<td></td>
</tr>
</table>
</BODY><!-- InstanceEnd --></HTML> |
Thanks for helping out
D
|