Visualizzazione dei risultati da 1 a 3 su 3

Discussione: Problema con un if

  1. #1

    Problema con un if

    Salve, ho una form di immissione dati con dei controlli if che vengono saltati, cioè nonostante i campi siano vuoti vengono inseriti nel database, mi dite perchè??
    Di seguito il codice semplicissimo della pagina.
    <%

    Dim str_wanted_rif, objconn, objrs, str_db_rif, rs_check_rif
    str_wanted_rif = Request.form("rif")
    SQL = "SELECT rif FROM contatti"
    set rs_check_rif=Server.CreateObject("ADODB.Recordset" )
    rs_check_rif.Open SQL,objConn
    Do While NOT rs_check_rif.EOF
    str_db_rif = rs_check_rif("rif")
    If str_db_rif = str_wanted_rif Then Response.Redirect("attenzione.asp?error=9")
    rs_check_rif.MoveNext
    Loop
    rs_check_rif.Close
    Set rs_check_rif = Nothing
    set objrs = Server.CreateObject("ADODB.Recordset")

    rif=Replace(Request.Form("rif"), "'", "''")
    data=Replace(Request.Form("data"), "'", "''")
    unit=Replace(Request.Form("unit"), "'", "''")
    proven=Replace(Request.Form("proven"), "'", "''")
    nomin=Replace(Request.Form("nomin"), "'", "''")
    recapito=Replace(Request.Form("recapito"), "'", "''")
    funz=Replace(Request.Form("funz"), "'", "''")
    lav=Replace(Request.Form("lav"), "'", "''")
    commenti=Replace(Request.Form("commenti"), "'", "''")

    if rif = "" then
    response.redirect("attenzione.asp?error=1")
    end if
    if data = "" then
    response.redirect("attenzione.asp?error=2")
    end if
    if unit = "" then
    response.redirect("attenzione.asp?error=3")
    end if
    if proven = "" then
    response.redirect("attenzione.asp?error=4")
    end if
    if nomin = "" then
    response.redirect("attenzione.asp?error=5")
    end if
    if recapito = "" then
    response.redirect("attenzione.asp?error=6")
    end if
    if funz = "" then
    response.redirect("attenzione.asp?error=7")
    end if
    if commenti = "" then
    response.redirect("attenzione.asp?error=8")
    end if


    SQL = "INSERT INTO contatti (rif, data, unit, proven, nomin, recapito, funz, lav, commenti) "
    SQL = SQL & "VALUES ('" & rif & "','" & data & "','" & unit & "','" & proven & "','" & nomin & "','" & recapito & "','" & funz & "','" & lav & "','" & commenti & "')"
    objrs.Open SQL, objconn


    response.redirect ("/xxxxx/xxxxxx/default.asp?unit="&unit&"")


    objconn.Close
    Set objconn = Nothing
    %>

  2. #2
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    La replace devi farla prima di inserire, non ha senso logico farla prima di controllare che il campo sia stato compilato.
    Inoltre il controllo prova a farlo così:

    codice:
    if rif &"[]" = "[]" then
    e così per gli altri...

    Roby

  3. #3
    Ho risolto con javascript, mille grazie comunque.

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 © 2026 vBulletin Solutions, Inc. All rights reserved.