ciao a tutti è giorni che cerco di risolvere questo problema ma niente, Ho creato un sito a un cliente: un utente si registra e dopo il login può ottenere un punto cliccando su un banner ( il punteggio viene visualizzato nella Home), fino a qui tutto ok, ma il problema è che a volte vengono aggiunti punti ad altri utenti o vengono aggiunti prima dopo pochi minuti dal click precedente (dovrebbero passare 24 ore)
La tabella utenti è:
La tabella points nel quale vengono aggiunti punti e la date:Codice:CREATE TABLE utenti ( id INT UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(30) NOT NULL, surname VARCHAR(30) NOT NULL, username VARCHAR(30) NOT NULL, password CHAR(32) NOT NULL, indirizzo VARCHAR( 100 ) NOT NULL, occupazione VARCHAR( 100 ) NOT NULL, temp SET( '0', '1' ) NOT NULL, regdate VARCHAR( 11 ) NOT NULL, uid VARCHAR( 32 ) NOT NULL, PRIMARY KEY(id), INDEX(username, password) );
La prima data viene aggiunta alla registrazione:Codice:CREATE TABLE points ( id VARCHAR( 32 ) NOT NULL, value INT UNSIGNED NOT NULL, date TIMESTAMP NOT NULL, FOREIGN KEY (id) REFERENCES utenti(uid) )
e questa è la funzione che dovrebbe aggiungere punti se la data nella tabella è precedente di 24 ore:Codice:<?php function reg_register($data){ //registro l'utente global $_CONFIG; $id = reg_get_unique_id(); mysql_query(" INSERT INTO ".$_CONFIG['table_utenti']." (name, surname, indirizzo, occupazione, username, password, temp, regdate, uid) VALUES ('".$data['name']."','".$data['surname']."','".$data['indirizzo']."', '".$data['occupazione']."','".$data['username']."',MD5('".$data['password']."'), '1', '".time()."','".$id."')"); //Decommentate la riga seguente per testare lo script in locale //echo "<a href=\"http://localhost/Articoli/autenticazione/2/scripts/confirm.php?id=".$id."\">Conferma</a>"; if(mysql_insert_id()){ if (mysql_query('INSERT INTO ' . $_CONFIG['table_points'] . ' (id, value, date) VALUES (\'' . $id . '\', 0, NOW())')) return reg_send_confirmation_mail($data['mail'], "prizeX@register", $id); else return REG_POINTS_FAILED; }else return REG_FAILED; }
Io non so più cosa fare, ho provato di tutto ma niente, non so dove sbaglio!Codice:<?php include_once("autenticazione/include/config.php"); include_once("autenticazione/include/auth.lib.php"); list($status, $user) = auth_get_status(); if($status == AUTH_LOGGED){ mysql_query('UPDATE utenti,points SET points.value=points.value+1, points.date=NOW() WHERE points.id=utenti.uid AND TO_DAYS(TIMEDIFF(NOW(), points.date)) >= 1'); } ?>
Questo è il manuale da cui ho preso le funzione time ecc...
http://dev.mysql.com/doc/refman/5.1/...functions.html

LinkBack URL
About LinkBacks
