[QUOTE]Originariamente inviato da net4fun
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 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;
}
}
httpObject = getHTTPObject();
function setOutput2(){
if(httpObject.readyState == 4){
document.getElementById('ns').value = httpObject.responseText;
}
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
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 '';
?>
in poche parole dovrei fare in modo che sia sicuro che la query INSERT INTO... sia stata completata per poi fare la SELECT COUNT...
ringrazio anticipatamente chi mi risponderà