Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13

Discussione: jquery invio dati post

  1. #1
    Utente bannato
    Registrato dal
    Mar 2011
    Messaggi
    389

    jquery invio dati post

    salve ho questo script che mi prende le info dal form e me le manda a un altro file che me le elabora.

    il problema e che sul database mi scrive undefinite.....nonostante il value è pieno
    forse con i codici è piu' chiaro


    index.php
    Codice PHP:
     <script type="text/javascript" src="../../../programmi/imagezoom/jquery-latest.js"></script>

    <script type="text/javascript" src="invio.js"></script>



     <form>
     <fieldset>
      <legend>Valutazione</legend>
    Bellezza

    1<input type="radio" name="bellezza" value="1" Change="valida();" />
    2<input type="radio" name="bellezza" onChange="valida();" value="2"/>
    3<input type="radio" name="bellezza" onChange="valida();" value="3"/>
    4<input type="radio" name="bellezza" onChange="valida();" value="4"/>
    5<input type="radio" name="bellezza" onChange="valida();" value="5"/>
    6<input type="radio" name="bellezza" onChange="valida();" value="6"/>
    7<input type="radio" name="bellezza" onChange="valida();" value="7"/>
    8<input type="radio" name="bellezza" onChange="valida();" value="8"/>
    9<input type="radio" name="bellezza" onChange="valida();" value="9"/>
    10<input type="radio" name="bellezza" onChange="valida();" value="10"/>

    <div id="message">
    </div>

    </fieldset>

    </form> 
    invio.js
    codice:
     // JavaScript Document
    function valida() {
    	var oXHR = new XMLHttpRequest();
    	oXHR.open("post","invio.php",true);
    	oXHR.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    	oXHR.onreadystatechange = function(){
    		
    			if(oXHR.readyState == 4){
    			var message = document.getElementById("message");
                if(oXHR.responseText =='OK'){
    				
    				message.innerHTML = "<p style=\"color:red\">Email gi&agrave; usata</p>";
    				}else{
    					message.innerHTML ="";
    					}
    					
    					
    					
    		}
    	}
    
    
    	var params ="bellezza=" + encodeURIComponent(document.forms[0].bellezza.value);
    	
    	oXHR.send(params);
    }
    invio.php
    Codice PHP:
    <?php require_once('../../../Connections/connessione.php'); ?>
    <?php
    if (!function_exists("GetSQLValueString")) {
    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      if (
    PHP_VERSION 6) {
        
    $theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
      }

      
    $theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

      switch (
    $theType) {
        case 
    "text":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;    
        case 
    "long":
        case 
    "int":
          
    $theValue = ($theValue != "") ? intval($theValue) : "NULL";
          break;
        case 
    "double":
          
    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
          break;
        case 
    "date":
          
    $theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
          break;
        case 
    "defined":
          
    $theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
          break;
      }
      return 
    $theValue;
    }
    }




    $trovato false;



     
    $insertSQL sprintf("INSERT INTO prova (bellezza) VALUES ( %s)",

                           
    GetSQLValueString($_POST['bellezza'], "text"));

      
    mysql_select_db($database_connessione$connessione);
      
    $Result1 mysql_query($insertSQL$connessione) or die(mysql_error());

    $trovato true;




    if(
    $trovato){
        
        echo 
    'OK';
        
    }else{

    echo 
    'KO';
    }

    ?>


    a scrivere sul database scrive.....solo mi scrive undefinite

  2. #2
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    "bellezza" non e' un solo campo, quando piu' campi hanno stesso name via javascript vanno trattati come in array
    quindi per determinare di quale dei document.forms[0].bellezza[x] vuoi prendere in considerazione il value devi ciclare

    var b=document.forms[0].bellezza;
    var segnato=-1;
    for(var x=0,l=b.length;x<l;x++){
    if(b[x].checked) segnato=x;
    break;
    }
    if(segnato!==-1){
    // qui fai quello che vuoi con b[segnato]
    }

  3. #3
    Utente bannato
    Registrato dal
    Mar 2011
    Messaggi
    389
    grazie per la risposta,
    tipo cosi intendi?


    codice:
     // JavaScript Document
    function valida() {
    	var oXHR = new XMLHttpRequest();
    	oXHR.open("post","invio.php",true);
    	oXHR.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    	oXHR.onreadystatechange = function(){
    		
    			if(oXHR.readyState == 4){
    			var message = document.getElementById("message");
                if(oXHR.responseText =='OK'){
    				
    				message.innerHTML = "<p style=\"color:red\">Email gi&agrave; usata</p>";
    				}else{
    					message.innerHTML ="";
    					}
    					
    					
    					
    		}
    	}
    
    var b=document.forms[0].bellezza.value;
    var segnato=-1;
    for(var x=0,l=b.length;x<l;x++){
    if(b[x].checked) segnato=x;
    break;
    }
    if(segnato!==-1){
    oXHR.send(params);
    }
    
    
    }

  4. #4
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    Originariamente inviato da Xinod
    // qui fai quello che vuoi con b[segnato]
    prima cosa facevi? non encodavi il value?
    var params ="bellezza=" + encodeURIComponent(b[segnato].value);

  5. #5
    Utente bannato
    Registrato dal
    Mar 2011
    Messaggi
    389
    ora mi dice b is undefinited e mi porta a questa riga

    for(var x=0,l=b.length;x<l;x++){

    ho scritto cosi come dicevi tu
    codice:
    // JavaScript Document
    function valida() {
    	var oXHR = new XMLHttpRequest();
    	oXHR.open("post","invio.php",true);
    	oXHR.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
    	oXHR.onreadystatechange = function(){
    		
    			if(oXHR.readyState == 4){
    			var message = document.getElementById("message");
                if(oXHR.responseText =='OK'){
    				
    				message.innerHTML = "<p style=\"color:red\">Email gi&agrave; usata</p>";
    				}else{
    					message.innerHTML ="";
    					}
    					
    					
    					
    		}
    	}
    
    var b=document.forms[0].bellezza.value;
    var segnato=-1;
    for(var x=0,l=b.length;x<l;x++){
    if(b[x].checked) segnato=x;
    break;
    }
    if(segnato!==-1){
    var params ="bellezza=" + encodeURIComponent(b[segnato].value);
    	
    	oXHR.send(params);
    
    }
    
    
    }

  6. #6
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    io ho scritto var b=document.forms[0].bellezza.value; ?

  7. #7
    Utente bannato
    Registrato dal
    Mar 2011
    Messaggi
    389
    hai ragione, ora ho messo cosi
    ma non funziona uguale....

    var b=document.forms[0].bellezza;

  8. #8
    Utente bannato
    Registrato dal
    Mar 2011
    Messaggi
    389
    forse ora sbaglio quando li scrivo nel database i dati??


    faccio una semplice query insert con $_POST['bellezza']

    dovrebbe andare ma niente

  9. #9
    Utente di HTML.it L'avatar di Xinod
    Registrato dal
    Sep 2000
    Messaggi
    13,649
    cambia
    if(b[x].checked) segnato=x;
    break;
    }
    in
    if(b[x].checked){
    segnato=x;
    break;
    }
    }

  10. #10
    Utente bannato
    Registrato dal
    Mar 2011
    Messaggi
    389
    scusami scusami a scrivere scrive.


    ma mi scrive solo il radio uno, se seleziono gli altri non me li scrive

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.