Skip to main content
September 7, 2011
Question

Database Connection Issues!!

  • September 7, 2011
  • 1 reply
  • 569 views

Dear Sir/Madam,

I have getting some problems regarding connection of database like Msaccess.

While i added data in database and similarly i created a form and related it. But when i bowse this file and hit the submit button the following errors are shown such as

And Also Please see the error code

<%@LANGUAGE="JAVASCRIPT"%>
<!--#include file="Connections/mycontact.asp" -->
<%
// *** Edit Operations: declare variables

// set the form action variable
var MM_editAction = Request.ServerVariables("SCRIPT_NAME");
if (Request.QueryString) {
  MM_editAction += "?" + Server.HTMLEncode(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_mycontact_STRING;
  var MM_editTable  = "Table1";
  var MM_editRedirectUrl = "thankyou.asp";
  var MM_fieldsStr = "ID|value|name|value|father_name|value|email|value|phone_no|value";
  var MM_columnsStr = "ID|none,none,NULL|name|',none,''|[father name]|',none,''|email|',none,''|[phone no]|',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));
  }

  // 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;
    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);
    }
  }

}
%>
<html>
<head>
<title>mycontactsss</title>


</head>

<body>
<form method="post" action="<%=MM_editAction%>" name="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">ID:</td>
      <td>
        <input type="text" name="ID" value="" size="32">
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Name:</td>
      <td>
        <input type="text" name="name" value="" size="32">
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Father name:</td>
      <td>
        <input type="text" name="father_name" value="" size="32">
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Email:</td>
      <td>
        <input type="text" name="email" value="" size="32">
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Phone no:</td>
      <td>
        <input type="text" name="phone_no" value="" size="32">
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"> </td>
      <td>
        <input type="submit" value="submit">
      </td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html>

If there is some mistakes in my process of connecting database and its execution please let me know the same..

thank You.

Roma

This topic has been closed for replies.

1 reply

Participating Frequently
September 7, 2011

We would need to see your connection file. Also, is there a good reason you are using Javascript rather than VBScript?

September 8, 2011

connection file??? i havent gt ur point,, did u mean in "image file" or in "code"??

Participating Frequently
September 8, 2011

I mean the file that contains the database connection details: Connections/mycontact.asp

Are you using dsn or dsn-less connection? Is the database open in MS Access? Have you set the IUSR permissions correctly? And again, why are you using Javascript?