Perform update and Insert in mysql via Asp classic

Asked

Viewed 970 times

1

Good morning Personal

I would like a help half boring can be up to something kind of banal

I have a page on Asp connects.Asp as follows

 <%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%

<%
dim conn

sub AbreConn()
'Criamos o objeto de conexão
Set conn = Server.CreateObject("ADODB.Connection") 

'Abrimos uma conexão com o banco de dados
conn.Open("DRIVER={MySQL ODBC 5.1 Driver};SERVER=server;PORT=3306;DATABASE=database;USER=usuario;PASSWORD=senha;OPTION=3;")
conexao_executa=true 

end sub

sub fechaConn()
'Fechamos a conexão com o banco de dados
conn.Close() 
'Destruímos o objeto
Set conn = Nothing
end sub

'sub que executara comandos no bd
sub executaconexao(comando)
    if conexao_executa=false then
        call AbreConn
    end if
    response.Write(comando)
    set objComando = Server.CreateObject("ADODB.Command")
    objComando.ActiveConnection = conn
    objComando.CommandText = comando
    objComando.Execute() 
    Set objComando = Nothing
    call fechaConn

end sub
%>

I can execute the select's usually gives no error however at the time of doing an update or Insert it does not perform anything, and also no error whatsoever.

If anyone has any hint of what can be done thank you.

below as I call the update on the send page.

sql ="update produtos set descricao_produto = '" & server.HTMLEncode(request.form("elm1")) & "' where codigo_chave = 32"

executaconexao(sql)
  • 1

    How the query is printed on the screen?

  • If there is no error, it is obviously because everything is running smoothly. Check if there really is a record with codigo_chave = 32, because if there is, it will not fail. Test this update without the clause where. So you will confirm that the records are indeed being updated.

  • Ah, and search for SQL Injection. :)

  • @Thiagolunardi excuse the delay in the reply I think it refers to some permission in the bank because using on another server was done the normal update has some idea of what type of permission should have?

  • Well, then it is a question of mysql. See on documentation on Grant. It should, if that’s the cause.

1 answer

1

Brother refitted his code and hope to have helped changed little thing ok

The detail is that you in the subset connection() do the verification of an object that only exists in Abreconn(), so you can’t check the IF without calling Abreconn() before ok.

I used Conn.execute() in the connected subexecutable() to decrease the code.

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>

<%
dim conn

sub AbreConn()
    'Criamos o objeto de conexão
    Set conn = Server.CreateObject("ADODB.Connection") 
    ''Abrimos uma conexão com o banco de dados
    'conn.Open("DRIVER={MySQL ODBC 5.1 Driver};SERVER=server;PORT=3306;DATABASE=database;USER=usuario;PASSWORD=senha;OPTION=3;")
    conexao_executa=true

    Servidor = "localhost"
    dsnName = "gsc" 'The name of the DSN
    dsnUser = "wilson" 'The username for the DSN
    dsnPass = "wilson26" 'The password for the DSN
    database = "gsc" 'The database to use
    stringer = "Provider=MSDASQL;Driver={MySQL ODBC 5.3 ANSI Driver};Server="&Servidor&";Database="&database&";User="&dsnUser&";Password="&dsnPass&";Option=3;"
    conn.Open stringer
end sub

sub fechaConn()
    'Fechamos a conexão com o banco de dados
    conn.Close() 
    'Destruímos o objeto
    Set conn = Nothing
end sub

'sub que executara comandos no bd
sub executaconexao(comando)
    call AbreConn()
    if conexao_executa=false then       
        conn.execute(comando)
        response.write comando
        call fechaConn()
    end if
end sub

sql = "insert into gsc.cadastro_cargo(cargo) values('boina verde');"
executaconexao(sql)

%>
  • thanks for the help that is another solution but the problem was with the bank the user providing me could not make changes in the bank but thanks for the help

Browser other questions tagged

You are not signed in. Login or sign up in order to post.