Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Fernando Franca

update record

Recommended Posts

Estou com um problema muito chato. Ja tentei resolver de varias formas e nada. Criei 3 paginas em asp que acessam meu BD para atualizar dados.

 

O Conceito e: mostra_atualiza.asp tenho um resumo de informacoes na atualizar_imoveis.asp tenho um Update Record criado a partir do Dreamweaver e na sucesso.asp tenho uma menssagem de sucesso caso seja alterado o registro.

 

O problema e que quando aperto o botao submit ele nao atualiza o registro mas tambem nao mostra nenhuma msg de erro. Ele simplesmente retorna ao valor antigo do campo.

 

Nao sei mais o que fazer por favor me ajudem.

 

A baixo segue o codigo:

 

mostra_atualiza.asp

 

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<!--#include virtual="/Connections/imoveis.asp" -->
<%
var Recordset1_cmd = Server.CreateObject ("ADODB.Command");
Recordset1_cmd.ActiveConnection = MM_imoveis_STRING;
Recordset1_cmd.CommandText = "SELECT * FROM imoveis";
Recordset1_cmd.Prepared = true;

var Recordset1 = Recordset1_cmd.Execute();
var Recordset1_numRows = 0;
%>
<%
var Repeat1__numRows = 10;
var Repeat1__index = 0;
Recordset1_numRows += Repeat1__numRows;
%>
<% 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);
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table border="1">
  <tr>
    <td>Id</td>
    <td>Negocio</td>
    <td>Cidade</td>
    <td>Tipo</td>
    <td>Quartos</td>
  </tr>
  <% while ((Repeat1__numRows-- != 0) && (!Recordset1.EOF)) { %>
    <tr>
      <td><a href="/atualizar_imoveis.asp?<%= Server.HTMLEncode(MM_keepBoth) + ((MM_keepBoth!="")?"&":"") + "ID=" + Recordset1.Fields.Item("ID").Value %>"><%=(Recordset1.Fields.Item("Id").Value)%></a></td>
      <td><%=(Recordset1.Fields.Item("Negocio").Value)%></td>
      <td><%=(Recordset1.Fields.Item("Cidade").Value)%></td>
      <td><%=(Recordset1.Fields.Item("Tipo").Value)%></td>
      <td><%=(Recordset1.Fields.Item("Quartos").Value)%></td>
    </tr>
    <%
  Repeat1__index++;
  Recordset1.MoveNext();
}
%>
</table>
</body>
</html>
<%
Recordset1.Close();
%>

 

atualizar_imoveis.asp

 

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<!--#include virtual="/Connections/imoveis.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;
%>
<%
if (String(Request("MM_update")) == "form1") {
  if (!MM_abortEdit) {
    // execute the update
	
    var MM_editCmd = Server.CreateObject ("ADODB.Command");
    MM_editCmd.ActiveConnection = MM_imoveis_STRING;
    MM_editCmd.CommandText = "UPDATE imoveis SET ID = ?, Referencia1 = ?, Negocio = ?, Referencia2 = ?, Bairro = ?, Referencia3 = ?, Cidade = ?, Foto2 = ?, Preco = ?, Foto3 = ?, Tipo = ?, Foto4 = ?, Quartos = ?, Foto5 = ?, Area = ?, Foto6 = ?, Foto1 = ?, Foto = ?, Descricao = ? WHERE ID = ?";
    MM_editCmd.Prepared = true;
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param1", 5, 1, -1, (String(Request.Form("Id")) != "undefined" && String(Request.Form("Id")) != "") ? Request.Form("Id") : null)); // adDouble
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param2", 202, 1, 255, Request.Form("Referencia1"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param3", 202, 1, 255, Request.Form("Negocio"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param4", 202, 1, 255, Request.Form("Referencia2"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param5", 202, 1, 255, Request.Form("Bairro"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param6", 202, 1, 255, Request.Form("Referencia3"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param7", 202, 1, 255, Request.Form("Cidade"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param8", 202, 1, 50, Request.Form("Foto2"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param9", 5, 1, -1, (String(Request.Form("Preco")) != "undefined" && String(Request.Form("Preco")) != "") ? Request.Form("Preco") : null)); // adDouble
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param10", 202, 1, 50, Request.Form("Foto3"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param11", 202, 1, 255, Request.Form("Tipo"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param12", 202, 1, 50, Request.Form("Foto4"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param13", 5, 1, -1, (String(Request.Form("Quartos")) != "undefined" && String(Request.Form("Quartos")) != "") ? Request.Form("Quartos") : null)); // adDouble
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param14", 202, 1, 50, Request.Form("Foto5"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param15", 5, 1, -1, (String(Request.Form("Area")) != "undefined" && String(Request.Form("Area")) != "") ? Request.Form("Area") : null)); // adDouble
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param16", 202, 1, 50, Request.Form("Foto6"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param17", 202, 1, 50, Request.Form("Foto1"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param18", 202, 1, 255, Request.Form("Foto"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param19", 202, 1, 255, Request.Form("Descricao"))); // adVarWChar
    MM_editCmd.Parameters.Append(MM_editCmd.CreateParameter("param20", 5, 1, -1, (String(Request.Form("MM_recordId")) != "undefined" && String(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
    var MM_editRedirectUrl = "/sucesso.asp";
    if (MM_editRedirectUrl && Request.QueryString && Request.QueryString.Count > 0) {
      MM_editRedirectUrl += ((MM_editRedirectUrl.indexOf('?') == -1) ? "?" : "&") + Request.QueryString;
    }
    Response.Redirect(MM_editRedirectUrl)
  }
}
%>
<%
var Recordset1__MMColParam = "1";
if (String(Request.QueryString("ID")) != "undefined" && 
    String(Request.QueryString("ID")) != "") { 
  Recordset1__MMColParam = String(Request.QueryString("ID"));
}
%>
<%
var Recordset1_cmd = Server.CreateObject ("ADODB.Command");
Recordset1_cmd.ActiveConnection = MM_imoveis_STRING;
Recordset1_cmd.CommandText = "SELECT * FROM imoveis WHERE ID = ?";
Recordset1_cmd.Prepared = true;
Recordset1_cmd.Parameters.Append(Recordset1_cmd.CreateParameter("param1", 5, 1, -1, Recordset1__MMColParam)); // adDouble

var Recordset1 = Recordset1_cmd.Execute();
var Recordset1_numRows = 0;
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form METHOD="post" ACTION="<%=MM_editAction%>" enctype="multipart/form-data" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td width="75" align="right" nowrap="nowrap">Id::</td>
      <td width="204"><input type="text" name="Id" value="<%=(Recordset1.Fields.Item("Id").Value)%>" size="32" /></td>
      <td width="75" align="right" nowrap="nowrap">Referencia1:</td>
      <td width="198"><input type="text" name="Referencia1" value="<%=(Recordset1.Fields.Item("Referencia1").Value)%>" size="32" />      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Negocio:</td>
      <td><input name="Negocio" type="text" value="<%=(Recordset1.Fields.Item("Negocio").Value)%>" size="32" <%=(Recordset1.Fields.Item("Negocio").Value)%> />      </td>
      <td align="right" nowrap="nowrap">Referencia2:</td>
      <td><input type="text" name="Referencia2" value="<%=(Recordset1.Fields.Item("Referencia2").Value)%>" size="32" />      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Bairro:</td>
      <td><input type="text" name="Bairro" value="<%=(Recordset1.Fields.Item("Bairro").Value)%>" size="32" />      </td>
      <td align="right" nowrap="nowrap">Referencia3:</td>
      <td><input type="text" name="Referencia3" value="<%=(Recordset1.Fields.Item("Referencia3").Value)%>" size="32" />      </td>
    </tr>
    <tr valign="baseline">
      <td height="24" align="right" nowrap="nowrap">Cidade:</td>
      <td><input type="text" name="Cidade" value="<%=(Recordset1.Fields.Item("Cidade").Value)%>" size="32" />      </td>
      <td align="right" nowrap="nowrap">Foto2:</td>
      <td><input type="text" name="Foto2" value="<%=(Recordset1.Fields.Item("Foto2").Value)%>" size="32" />      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Preco:</td>
      <td><input type="text" name="Preco" value="<%=(Recordset1.Fields.Item("Preco").Value)%>" size="32" />      </td>
      <td height="24" align="right" nowrap="nowrap">Foto3:</td>
      <td><input type="text" name="Foto3" value="<%=(Recordset1.Fields.Item("Foto3").Value)%>" size="32" />      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Tipo:</td>
      <td><input type="text" name="Tipo" value="<%=(Recordset1.Fields.Item("Tipo").Value)%>" size="32" />      </td>
      <td align="right" nowrap="nowrap">Foto4:</td>
      <td><input type="text" name="Foto4" value="<%=(Recordset1.Fields.Item("Foto4").Value)%>" size="32" />      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Quartos:</td>
      <td><input type="text" name="Quartos" value="<%=(Recordset1.Fields.Item("Quartos").Value)%>" size="32" />      </td>
      <td align="right" nowrap="nowrap">Foto5:</td>
      <td><input type="text" name="Foto5" value="<%=(Recordset1.Fields.Item("Foto5").Value)%>" size="32" />      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Area:</td>
      <td><input type="text" name="Area" value="<%=(Recordset1.Fields.Item("Area").Value)%>" size="32" />      </td>
      <td align="right" nowrap="nowrap">Foto6:</td>
      <td><input type="text" name="Foto6" value="<%=(Recordset1.Fields.Item("Foto6").Value)%>" size="32" />      </td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap">Foto1:</td>
      <td><input type="text" name="Foto1" value="<%=(Recordset1.Fields.Item("Foto1").Value)%>" size="32" />      </td>
      <td align="right" nowrap="nowrap">Foto:</td>
      <td><input type="text" name="Foto" value="<%=(Recordset1.Fields.Item("Foto").Value)%>" size="32" />      </td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap">Descricao:</td>
      <td align="right" nowrap="nowrap"><div align="left">
        <textarea name="Descricao" cols="32"><%=(Recordset1.Fields.Item("Descricao").Value)%></textarea>
      </div></td>
      <td align="right" nowrap="nowrap"> </td>
      <td align="right" nowrap="nowrap"> </td>
    </tr>
    <tr valign="baseline">
      <td height="24" align="right" nowrap="nowrap"> </td>
      <td align="right" nowrap="nowrap"> </td>
      <td> </td>
      <td align="right" nowrap="nowrap"> </td>
    </tr>
    <tr valign="baseline">
      <td align="right" nowrap="nowrap"> </td>
      <td height="24" align="right" nowrap="nowrap"> </td>
      <td> </td>
      <td><input type="submit" value="Update record" />      </td>
    </tr>
  </table>
  <p> </p>

    <input type="hidden" name="MM_update" value="form1" />
  <input type="hidden" name="MM_recordId" value="<%= Recordset1.Fields.Item("ID").Value %>" />
</form>
<p> </p>
</body>
</html>
<%
Recordset1.Close();
%>

 

sucesso.asp

 

 

<%@LANGUAGE="JAVASCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
Registro atualizado com sucesso!!!
</body>
</html>

Obrigado.

Compartilhar este post


Link para o post
Compartilhar em outros sites

olha este exemplo

Compartilhar este post


Link para o post
Compartilhar em outros sites

Velho... dentro do code asp não pode ter esse tipo de code

 

// create the list of parameters which should not be maintained

 

o certo seria colocar

 

'create the list of parameters which should not be maintained

 

nesse caso são comentários.... o uso de // é para javascript, no caso comentar code

 

o ' serve para comentar code no asp

 

Com isso tudo que estiver dentro da tag asp ou seja.... dentro da tag <% tudo aqui dentro %> não pode ter comentários com //

Compartilhar este post


Link para o post
Compartilhar em outros sites

Velho... dentro do code asp não pode ter esse tipo de code

 

// create the list of parameters which should not be maintained

 

o certo seria colocar

 

'create the list of parameters which should not be maintained

 

nesse caso são comentários.... o uso de // é para javascript, no caso comentar code

 

o ' serve para comentar code no asp

 

Com isso tudo que estiver dentro da tag asp ou seja.... dentro da tag <% tudo aqui dentro %> não pode ter comentários com //

 

Tinha feito tudo em asp JavaScript Mas ja passei tudo a VB porem sem sucesso na solucao.

 

Quando conseguir posto novamente.

Compartilhar este post


Link para o post
Compartilhar em outros sites

Velho o que estou achando estranho é esse

 

enctype="multipart/form-data" no form... tente tirar ele e faça o teste.

 

Isso ai é utilizando para upload de fotos por exemplo...

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.