Salve a tutti,
Vengo subito al problema. Questa query non è "sicura"
codice:
mysql_query("SELECT COUNT(*) AS count FROM RegistrazioneSchedine WHERE data= '$data' AND Nickname= '$_GET[username]'");
mi restituisce a volte valori non veri, ho notato che a volte inizia con zero ed è impossibile perchè quando viene effettuata c'è già almeno una registrazione, poi a volte è un valore in meno di quelli realmente registrati, però alla registrazione successiva ritorna alla normalità facendo salti (dipende quanti valori non ha contato precedentemente)

Questo è il codice:
codice:
			function getHTTPObject(){
			   if (window.ActiveXObject) return new ActiveXObject("Microsoft.XMLHTTP");
			   else if (window.XMLHttpRequest) return new XMLHttpRequest();
			   else {
				  alert("Your browser does not support AJAX.");
				  return null;
			   }
			}   
 
			function setOutput(){
				if(httpObject.readyState == 4){
					document.getElementById('numero1').value = httpObject.responseText;	
					document.getElementById('numero2').value = httpObject.responseText;
					document.getElementById('numero3').value = httpObject.responseText;
					document.getElementById('numero4').value = httpObject.responseText;
					document.getElementById('numero5').value = httpObject.responseText;									
				}
			 
			}
			 
			function doWork(){    
				httpObject = getHTTPObject();
				if (httpObject != null) {
					httpObject.open("GET", "components/com_jumi/files/elabora.php?username="
									+document.getElementById('username').value+"&numero1="
									+document.getElementById('numero1').value+"&numero2="
									+document.getElementById('numero2').value+"&numero3="
									+document.getElementById('numero3').value+"&numero4="
									+document.getElementById('numero4').value+"&numero5="
									+document.getElementById('numero5').value, true);
					httpObject.send(null); 
					httpObject.onreadystatechange = setOutput;
				}
				
				
				function setOutput2(){
					if(httpObject.readyState == 4){
						document.getElementById('ns').value = httpObject.responseText;
						var ns =  document.getElementById('ns').value;
						if(ns>=1){
							document.getElementById("n1").style.background="url(components/com_jumi/files/blue.png)";}
						if(ns>=2){
							document.getElementById("n2").style.background="url(components/com_jumi/files/blue.png)";}
						if(ns>=3){
							document.getElementById("n3").style.background="url(components/com_jumi/files/blue.png)";}
						if(ns>=4){
							document.getElementById("n4").style.background="url(components/com_jumi/files/blue.png)";}
						if(ns>=5)
							document.getElementById("n5").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=6)
							document.getElementById("n6").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=7)
							document.getElementById("n7").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=8)
							document.getElementById("n8").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=9)
							document.getElementById("n9").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=10)
							document.getElementById("n10").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=11)
							document.getElementById("n11").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=12)
							document.getElementById("n12").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=13)
							document.getElementById("n13").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=14)
							document.getElementById("n14").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=15)
							document.getElementById("n15").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=16)
							document.getElementById("n16").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=17)
							document.getElementById("n17").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=18)
							document.getElementById("n18").style.background="url(components/com_jumi/files/blue.png)";
						if(ns>=19)
							document.getElementById("n19").style.background="url(components/com_jumi/files/blue.png)";
						if(ns==20)
							document.getElementById("n20").style.background="url(components/com_jumi/files/blue.png)";
								
					} 
				 
				}	//fine setOutput2
				
				
			    
				httpObject = getHTTPObject();
				
				if (httpObject != null) {
					httpObject.open("GET", "components/com_jumi/files/ns.php?username="
									+document.getElementById('username').value, true);
					httpObject.send(null); 
					httpObject.onreadystatechange = setOutput2;
					
				}
			
				
				
				
				
			}//fine doWork
			 
			var httpObject = null;
ns.php
Codice PHP:
<?php 
    $db_host 
"****"
    
$db_user "****"
    
$db_password "****"
    
$db_name "****";  
                     
            
$db mysql_connect($db_host$db_user$db_password);
                  
mysql_select_db($db_name$db);

            
$data=date("d-m-Y");
        
        
$query mysql_query("SELECT COUNT(*) AS count FROM RegistrazioneSchedine WHERE data= '$data' AND Nickname= '$_GET[username]'");     
        
$sql mysql_fetch_array($query);  
        
$_GET['ns'] = $sql['count'];
                    
    
mysql_close($db); 
           
    if (isset(
$_GET['ns']))
        echo 
$_GET['ns'];
   
 
?>
elabora.php
Codice PHP:
<?php 


    $db_host 
"****"
    
$db_user "*****"
    
$db_password "****"
    
$db_name "*****";                   
            
$db mysql_connect($db_host$db_user$db_password);
                  
mysql_select_db($db_name$db);

            
$data=date("d-m-Y"); $ora=date("H:i:s");

        
mysql_query("INSERT INTO RegistrazioneSchedine(Nickname, numero1, numero2, numero3, numero4, numero5, data, ora) 
                     VALUE ('
$_GET[username]', '$_GET[numero1]', '$_GET[numero2]', '$_GET[numero3]', '$_GET[numero4]', '$_GET[numero5]', '$data', '$ora')");
                    
    
mysql_close($db); 
           
    if (isset(
$_GET['numero1']))
        echo 
'';    

    if (isset(
$_GET['numero2']))
        echo 
'';    

    if (isset(
$_GET['numero3']))
        echo 
'';    

    if (isset(
$_GET['numero4']))
        echo 
'';    
        
    if (isset(
$_GET['numero5']))
        echo 
'';    
    
?>
secondo me effettua la query
codice:
$query = mysql_query("SELECT COUNT(*) AS count FROM RegistrazioneSchedine WHERE data= '$data' AND Nickname= '$_GET[username]'"); $sql = mysql_fetch_array($query); $_GET['ns'] = $sql['count'];
prima che viene salvata la query
codice:
mysql_query("INSERT INTO RegistrazioneSchedine(Nickname, numero1, numero2, numero3, numero4, numero5, data, ora) VALUE ('$_GET[username]', '$_GET[numero1]', '$_GET[numero2]', '$_GET[numero3]', '$_GET[numero4]', '$_GET[numero5]', '$data', '$ora')");
quindi dipende tutto dai tempi di queste due...se il db non fa in tempo a salvare prima la seconda query che ho scritto avrà ns con un valore in meno...spero di essere stato chiaro..

ringrazio anticipatamente chi mi risponderà