Visualizzazione dei risultati da 1 a 10 su 10
  1. #1

    Syntax error in INSERT INTO statement

    Salve, ho creato un sito, e una pagina alla quale accedendo è possibile aggiornare/inserire/eliminare record al database.

    ora, devo inserire alcuni dati al database attraverso un modulo, e questo modulo comprende 22 campi, 18 numerici, 2 di testo e due menù a tendina, filtrati su valori associati di un altra tabella collegata.

    per intenderci, devo inserire le statistiche di un giocatore, punti fatti, rimbalzi, assist e via dicendo.
    I menù a tendina in pratica devono darmi l'id della partita e del giocatore in questione.

    quando però provo la pagina in locale mi viene questo errore

    Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

    [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.

    /aggiungi_statistiche.asp, line 135

  2. #2
    sarebbe interessante vedere l'istruzione, non solo l'errore

  3. #3
    io ci metto tutto il codice VBScript che mi ha compilato Dreamweaver, in grasseto la linea a cui corrisponde l'errore...

    -------------------------------------------------------------------------

    <%@LANGUAGE="VBSCRIPT"%>
    <%
    ' *** Restrict Access To Page: Grant or deny access to this page
    MM_authorizedUsers=""
    MM_authFailedURL="errore.asp"
    MM_grantAccess=false
    If Session("MM_Username") <> "" Then
    If (true Or CStr(Session("MM_UserAuthorization"))="") Or _
    (InStr(1,MM_authorizedUsers,Session("MM_UserAuthor ization"))>=1) Then
    MM_grantAccess = true
    End If
    End If
    If Not MM_grantAccess Then
    MM_qsChar = "?"
    If (InStr(1,MM_authFailedURL,"?") >= 1) Then MM_qsChar = "&"
    MM_referrer = Request.ServerVariables("URL")
    if (Len(Request.QueryString()) > 0) Then MM_referrer = MM_referrer & "?" & Request.QueryString()
    MM_authFailedURL = MM_authFailedURL & MM_qsChar & "accessdenied=" & Server.URLEncode(MM_referrer)
    Response.Redirect(MM_authFailedURL)
    End If
    %>

    <%
    ' *** Edit Operations: declare variables

    Dim MM_editAction
    Dim MM_abortEdit
    Dim MM_editQuery
    Dim MM_editCmd

    Dim MM_editConnection
    Dim MM_editTable
    Dim MM_editRedirectUrl
    Dim MM_editColumn
    Dim MM_recordId

    Dim MM_fieldsStr
    Dim MM_columnsStr
    Dim MM_fields
    Dim MM_columns
    Dim MM_typeArray
    Dim MM_formVal
    Dim MM_delim
    Dim MM_altVal
    Dim MM_emptyVal
    Dim MM_i

    MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
    If (Request.QueryString <> "") Then
    MM_editAction = MM_editAction & "?" & Request.QueryString
    End If

    ' boolean to abort record edit
    MM_abortEdit = false

    ' query string to execute
    MM_editQuery = ""
    %>
    <%
    ' *** Insert Record: set variables

    If (CStr(Request("MM_insert")) = "Stat") Then

    MM_editConnection = MM_nomeconnessione_STRING
    MM_editTable = "Nome_Tabella"
    MM_editRedirectUrl = "nomepagina.asp"
    MM_fieldsStr = "select|value|select2|value|giocatore|value|Q|valu e|MT|value|PTI|value|TLF|value|TLT|value|T2F|value |T2T|value|T3F|value|T3T|value|RD|value|RO|value|P P|value|PR|value|AS|value|STD|value|STS|value|FF|v alue|FS|value|VAL|value"
    MM_columnsStr = "idGara|none,none,NULL|idPlayer|none,none,NULL|Gio catore|',none,''|Q|',none,''|MT|none,none,NULL|PTI |none,none,NULL|TLF|none,none,NULL|TLT|none,none,N ULL|T2F|none,none,NULL|T2T|none,none,NULL|T3F|none ,none,NULL|T3T|none,none,NULL|RD|none,none,NULL|RO |none,none,NULL|PP|none,none,NULL|PR|none,none,NUL L|AS|none,none,NULL|STD|none,none,NULL|STS|none,no ne,NULL|FF|none,none,NULL|FS|none,none,NULL|VAL|no ne,none,NULL"

    ' create the MM_fields and MM_columns arrays
    MM_fields = Split(MM_fieldsStr, "|")
    MM_columns = Split(MM_columnsStr, "|")

    ' set the form values
    For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
    Next

    ' append the query string to the redirect URL
    If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
    If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
    MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
    Else
    MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
    End If
    End If

    End If
    %>
    <%
    ' *** Insert Record: construct a sql insert statement and execute it

    Dim MM_tableValues
    Dim MM_dbValues

    If (CStr(Request("MM_insert")) <> "") Then

    ' create the sql insert statement
    MM_tableValues = ""
    MM_dbValues = ""
    For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
    MM_formVal = MM_fields(MM_i+1)
    MM_typeArray = Split(MM_columns(MM_i+1),",")
    MM_delim = MM_typeArray(0)
    If (MM_delim = "none") Then MM_delim = ""
    MM_altVal = MM_typeArray(1)
    If (MM_altVal = "none") Then MM_altVal = ""
    MM_emptyVal = MM_typeArray(2)
    If (MM_emptyVal = "none") Then MM_emptyVal = ""
    If (MM_formVal = "") Then
    MM_formVal = MM_emptyVal
    Else
    If (MM_altVal <> "") Then
    MM_formVal = MM_altVal
    ElseIf (MM_delim = "'") Then ' escape quotes
    MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
    Else
    MM_formVal = MM_delim + MM_formVal + MM_delim
    End If
    End If
    If (MM_i <> LBound(MM_fields)) Then
    MM_tableValues = MM_tableValues & ","
    MM_dbValues = MM_dbValues & ","
    End If
    MM_tableValues = MM_tableValues & MM_columns(MM_i)
    MM_dbValues = MM_dbValues & MM_formVal
    Next
    MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"

    If (Not MM_abortEdit) Then
    ' execute the insert
    Set 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 <> "") Then
    Response.Redirect(MM_editRedirectUrl)
    End If
    End If

    End If
    %>
    <%
    Dim rsAgStat
    Dim rsAgStat_numRows

    Set rsAgStat = Server.CreateObject("ADODB.Recordset")
    rsAgStat.ActiveConnection = MM_nomeconnessione_STRING
    rsAgStat.Source = "SELECT * FROM Nome_Tabella"
    rsAgStat.CursorType = 0
    rsAgStat.CursorLocation = 2
    rsAgStat.LockType = 1
    rsAgStat.Open()

    rsAgStat_numRows = 0
    %>

  4. #4
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    codice:
    MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"
    Response.Write MM_editQuery
    Response.end
    E verifica quello che hai a video.

    Roby

  5. #5
    a video mi viene questo

    insert into Nome_Tabella (idGara,idPlayer,Giocatore,Q,MT,PTI,TLF,TLT,T2F,T2 T,T3F,T3T,RD,RO,PP,PR,AS,STD,STS,FF,FS,VAL) values (1,1,'Nome','B',1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 1)

    ho cambiato la porzione di codice, ho inserito a tutti i valori numeri 1

  6. #6
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Forse il campo AS devi scriverlo tra parentesi quadre: [AS]

    Roby

  7. #7
    per sicurezza li metterei TUTTI fra parentesi quadre. meglio, cambierei proprio i nomi nel db, per non avere gli stessi problemi da altre parti (tanto i comandi sono a composizione automatica...)

  8. #8
    non vi seguo... dov'è che dovrei mettere le quadre e perchè?

    che problemi può dare la voce AS?

    scusate, ma sono un po all'ABC riguardo a programmazione, finora mi sono sempre avvalso degli strumenti di Dreamweaver...

  9. #9
    sql ha delle parole riservate, e non puoi ovviamente usarle come nome per campi o tabelle (ti immagini SELECT SELECT FROM FROM?). qui un elenco http://support.microsoft.com/default...;en-us;q109312

    agisci di conseguenza

  10. #10
    sei il mio eroe... ho cambiato come mi hai suggerito AS con AST e per magia mi è andato tutto perfettamente...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.