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

    salvare in un DB il risultato di una checkbox

    ho alcune checkbox e a secondo se vengono checcate o meno nel database deve essere inserito "si.jpg" oppure "no.jpg"

    come faccio a recuperare il loro valore per poi fare la insert??

    codice:
    <tr> 
          <td width="101" height="19" bgcolor="#FFFF00"><font face="Arial Narrow" size="2">opzione 02</font></td>
          <td width="277" height="19">
          <input type="checkbox" name="opzione02" value="opzione02"></td>
        </tr>
    ..: Serie A :..
    ..: FORZA PALERMOOOOoooo.....

  2. #2
    Moderatore di ASP e MS Server L'avatar di Roby_72
    Registrato dal
    Aug 2001
    Messaggi
    19,559
    Se recuperi il "name" cosa ottieni???
    Metti value=""

  3. #3
    Guarda, il valore del checkbox è quello che gli imposti tu...

    Ora se ad esempio fai

    codice:
    <input name="casella" type="checkbox" value="true">
    Nella pagina successiva potai fare, per ottenere un valore booleano:

    codice:
    Dim blnVar
    Dim varFinale
    
    blnVar = CBool(Request.Form("casella"))
    
    If blnVar = True Then
      varFinale = "si.jpg"
    Else
      varFinale = "no.jpg"
    End If
    Oppure puoi fare
    codice:
    <input name="casella" type="checkbox" value="si.jpg">
    e poi nella pagina successiva

    codice:
    Dim varFinale
    
    varFinale = Request.Form("casella")
    If varFinale = "" Then varFinale = "no.jpg"

    Buh cmq ad ogni modo ti consiglio il primo metodo
    anche semanticamente è più corretto.

    Bye
    SGr33n

  4. #4
    Scusate ma non mi sono spiegato... posto il codice per essere piu chiaro:
    ho una pagina dalla quale faccio un upload di alcuni dati e di alcune immagini.
    I dati e le immagini funzionano alla grande, il problema mi si pone quando devo caricare sul database le opzioni(checkboox)..
    Se l'utente mette la spunta allora devo caricare "si.jpg" altrimenti devo caricare "no.jpg"



    scheda_nuovo_utente.htm
    codice:
    <form action="upload.asp" method="post" enctype="multipart/form-data">
      <div align="center">
        <center>
      <table width="386" border="0" style="border-collapse: collapse" bordercolor="#111111" cellpadding="2" height="488">
        <tr> 
          <td width="101" height="19"></td>
          <td width="277" height="19"></td>
        </tr>
        <tr> 
          <td width="101" height="24"><font face="Arial Narrow" size="2">Cognome</font></td>
          <td width="277" height="24">
          <input name="cognome" type="text" id="cognome" style="border-style: solid; border-width: 1" size="15"></td>
        </tr>
        <tr> 
          <td width="101" height="24"><font face="Arial Narrow" size="2">Nome</font></td>
          <td width="277" height="24">
          <input name="nome" type="text" id="nome" style="border-style: solid; border-width: 1" size="15"></td>
        </tr>
        <tr> 
          <td width="101" height="24"><font face="Arial Narrow" size="2">Citta</font></td>
          <td width="277" height="24">
          <input name="citta" type="text" id="citta" size="15" style="border-style: solid; border-width: 1"></td>
        </tr>
        <tr> 
          <td width="101" height="19"></td>
          <td width="277" height="19"></td>
        </tr>
        <tr> 
          <td width="101" height="21"><font face="Arial Narrow" size="2">opzione 01</font></td>
          <td width="277" height="21">
          <input type="checkbox" name="opzione01" value="si.gif"></td>
        </tr>
        <tr> 
          <td width="101" height="19"><font face="Arial Narrow" size="2">opzione 02</font></td>
          <td width="277" height="19">
          <input type="checkbox" name="opzione02" value="si.gif"></td>
        </tr>
        <tr> 
          <td width="101" height="19"><font face="Arial Narrow" size="2">opzione 03</font></td>
          <td width="277" height="19">
          <input type="checkbox" name="opzione03" value="si.gif"></td>
        </tr>
        <tr> 
              <td width="101" height="20"></td>
          <td width="277" height="20">
          </td>
        </tr>
        <tr> 
              <td width="101" height="20"><font face="Arial Narrow" size="2">foto 01:</font></td>
          <td width="277" height="20">
          <input type="file" name="file1" size="18" style="border-style: solid; border-width: 1"></td>
        </tr>
        <tr> 
          <td width="101" height="20"><font face="Arial Narrow" size="2">foto 02:</font></td>
          <td width="277" height="20"><input name="file2" type="file" id="file2" style="border-style: solid; border-width: 1" size="18"></td>
        </tr>
        <tr> 
          <td width="101" height="24"></td>
          <td width="277" height="24"></td>
        </tr>
        <tr> 
          <td width="101" height="19"></td>
          <td width="277" height="19">
              <input name="submit" type="submit" value="   Invia   " style="border-style: solid; border-width: 1"></td>
        </tr>
        </table>
        </center>
      </div>
      </form>





    upload.asp
    codice:
    <%
    'Questa variabile setta il percorso di dove effettuare l'upolad
    	percorso = "/public/immagini/"
    	
    ' Setto le variabili per la data
    	miaData = Now
    
    'Estrapolo il giorno
    	gg = Day(miaData)
    
    'Estrapolo il mese
    	mm = Month(miaData)
    
    'Estrapolo l'anno
    	aa = Year(miaData)
    
    'Estrapolo le ore
    	h = Hour(miaData)
    
    'Estrapolo i minuti
    	m = Minute(miaData)
    
    'Estrapolo i secondi
    	s = Second(miaData)
    
    ByteRicevuti = Request.TotalBytes
    
    if ByteRicevuti > 0 then
    	DatiRicevuti = Request.BinaryRead(ByteRicevuti)
    	For i = 1 To lenB(DatiRicevuti)
    		FileBinario = FileBinario & chr(ascB(midB(DatiRicevuti,i,1)))
    	Next
    	FirmaFile = left(FileBinario,instr(FileBinario,"" & vbCrLf)-1)
    	ArrPezzi = split(FileBinario,FirmaFile)
    
    	for item = 1 to ubound(ArrPezzi)-1
    		Inizio = instr(ArrPezzi(item),"" & vbCrLf & "" & vbCrLf)
    		Intestazione = left(ArrPezzi(item),Inizio-1)
    		Inizio = Inizio + len("" & vbCrLf) + len("" & vbCrLf)
    	    	ContenutoFile =    mid(ArrPezzi(item),Inizio,len(ArrPezzi(item))-Inizio-1)
    
    ' Recupero i campi se sono compilati
    		if instr(Intestazione,"cognome") > 0 then
    			cognome = ContenutoFile
    		end if
    
    		if instr(Intestazione,"nome") > 0 then
    			nome = ContenutoFile
    		end if
    		
    		if instr(Intestazione,"citta") > 0 then
    			citta = ContenutoFile
    		end if
    		
    		
    'controllo i valori dei checkbox
    		if instr(Intestazione,"opzione01") > 0 then
    			opzione01 = ContenutoFile
    		end if
    		
    		if instr(Intestazione,"opzione02") > 0 then
    			opzione02 = ContenutoFile
    			
    		end if
    		
    		if instr(Intestazione,"opzione03") > 0 then
    			opzione03= ContenutoFile
    		end if   
    		
    
    ' Qui recupero il file da uploadare (se presente) e lo scrivo sul server
    		if instr(Intestazione,"file1") > 0 then
    		    i = instr(Intestazione,"filename=")
    			j = instr(i + 10,Intestazione,chr(34))
    			NomeUpload = mid(Intestazione,i + 10,j-i-10)
    			i = instrRev(NomeUpload,"\")
    			if i<>0 then
        		    NomeFile = mid(NomeUpload,i + 1)
        		else
        			NomeFile = NomeUpload
        		end if
          		if i<>0 then
    				Set FSO = CreateObject("Scripting.FileSystemObject")
    				Upload1 = True
    				DimensioneFile1 = len(ContenutoFile)
    				EstensioneFile1 = right(ContenutoFile,3)
    				NomeFile1 = gg & "-" & mm & "-" & aa & "-" & h & "-" & m & "-" & s & "-" & NomeFile
    				image_path_file1 ="/public/immagini/" & NomeFile1
        			Set textStream = FSO.CreateTextFile(server.mappath(percorso & NomeFile1), True, False)
        			textStream.Write ContenutoFile
        			textStream.Close
        			Set textStream = Nothing
    	   			Set FSO = Nothing
    			else
    			image_path_file1 ="/public/immagini/nessuna_immagine.jpg" 
    			end if
    		end if
    		
    		if instr(Intestazione,"file2") > 0 then
    		    i = instr(Intestazione,"filename=")
    			j = instr(i + 10,Intestazione,chr(34))
    			NomeUpload = mid(Intestazione,i + 10,j-i-10)
    			i = instrRev(NomeUpload,"\")
    			if i<>0 then
        		    NomeFile = mid(NomeUpload,i + 1)
        		else
        			NomeFile = NomeUpload
        		end if
    			if i<>0 then
    				Set FSO = CreateObject("Scripting.FileSystemObject")
    				Upload2 = True
    				DimensioneFile2 = len(ContenutoFile)
    				EstensioneFile2 = right(ContenutoFile,3)
    				NomeFile2 = gg & "-" & mm & "-" & aa & "-" & h & "-" & m & "-" & s & "-" & NomeFile
    				image_path_file2 ="/public/immagini/" & NomeFile2
        			Set textStream = FSO.CreateTextFile(server.mappath(percorso & NomeFile2), True, False)
        			textStream.Write ContenutoFile
        			textStream.Close
        			Set textStream = Nothing
    	   			Set FSO = Nothing
    			else
    			image_path_file2 ="/public/immagini/nessuna_immagine.jpg" 
    			end if
    		end if
    
    	next 
    	
    dim cn, sql	
    set cn = Server.CreateObject("ADODB.Connection") 
    cn.connectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;"&_ 
    "Persist Security Info=False;"&_ 
    "Data Source="& Server.MapPath("/mdb-database/db_utenti.mdb") 
    cn.open() 
    
    
    if Upload1 = true Or Upload2 = true  then
    	foto = "SI"
    	sql = "INSERT INTO schede(cognome, nome, citta, path_immagine_file1, path_immagine_file2, foto,opzione01, opzione02, opzione03) VALUES( '"&cognome&"','"&nome&"','"&citta&"','"&image_path_file1&"','"&image_path_file2&"','"& foto &"','"& opzione01 &"','"& opzione02 &"','"& opzione03 &"')" 
    response.write(sql)
    else
    	foto = "NO"
    	sql = "INSERT INTO schede(cognome, nome, citta, path_immagine_file1, path_immagine_file2, foto,opzione01, opzione02, opzione03) VALUES( '"&cognome&"','"&nome&"','"&citta&"','"&image_path_file1&"','"&image_path_file2&"','"& foto &"','"& opzione01 &"','"& opzione02 &"','"& opzione03 &"')" 
    response.write(sql)
    end if
    
    cn.execute(sql) 
    cn.close() 
    set cn = nothing 
    
    'Verifico tutto l'upload effettuato
    Response.Write "
    Cognome: " & cognome & "
    "
    Response.Write "Nome: " & nome & "
    "
    Response.Write "Città: " & citta & "
    "
    Response.Write "Opzioni: 
    "
    Response.Write "Opzione 01: " & opzione01 & "
    "
    Response.Write "Opzione 02: " & opzione02 & "
    "
    Response.Write "Opzione 03: " & opzione03 & "
    "
    
    
    If Upload1 = true then
    	Response.Write "
    Il nome del file1 che hai uploadato è: " & NomeFile1 & "
    "
    	Response.Write "La dimensione è di " & DimensioneFile1*0.001 & "kb
    "
    
    End If
    
    If Upload2 = true then
    	Response.Write "
    Il nome del file2 che hai uploadato è: " & NomeFile2 & "
    "
    	Response.Write "La dimensione è di " & DimensioneFile2*0.001 & "kb
    "
    
    End If
    End If
    
    %>
    ..: Serie A :..
    ..: FORZA PALERMOOOOoooo.....

  5. #5
    Lascio a chi ha più pazienza\tempo per leggersi tutto, :P
    SGr33n

  6. #6
    sintetizzano:

    se nella pagina di inserimento uso:
    codice:
    <form action="upload.asp" method="post" enctype="multipart/form-data">
    posso usare il request.form per ricavarmi il valore del checkbox?
    ..: Serie A :..
    ..: FORZA PALERMOOOOoooo.....

  7. #7
    No che non puoi...

    Ti indico una guida dove troverai istruzioni su come fare... Bye

    http://freeasp.html.it/articoli/view...olo.asp?id=169
    SGr33n

  8. #8
    grazie per la guida mi sara' molto utile e la leggero' anche se ho aggirato il problema usando un altro metodo:
    al posto delle checkbox ho usato i radiobotton
    ..: Serie A :..
    ..: FORZA PALERMOOOOoooo.....

  9. #9
    Vabbè in termini tecnici non cambia molto... anche se il radio button va meglio in termini pratici.

    Bye
    SGr33n

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.