Visualizzazione dei risultati da 1 a 9 su 9

Discussione: Registrazione utenti

  1. #1
    Utente di HTML.it L'avatar di lukezz
    Registrato dal
    Feb 2010
    Messaggi
    494

    Registrazione utenti

    Salve, ho seguito la guida che c'è nel sito per la registrazione utenti.
    per creare le tabelle ho fatto una pagina install.php con il seguente codice:

    Codice PHP:
    <?PHP include("include/config.php");  $query"CREATE TABLE sessioni (    uid CHAR(32) NOT NULL,    user_id INT UNSIGNED NOT NULL,    creation_date INT UNSIGNED NOT NULL,    INDEX(uid) )"$result mysql_query($query);   if ($result == 1){echo "tabelle sessioni create.";} else{echo "errore creazione tabelle sessioni
    "
    ;}  $query2 "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,    PRIMARY KEY(id),    INDEX(username, password) )"$result2 mysql_query($query2);   if ($result2 == 1){echo "tabella utenti creata.";} else{echo "errore creazione tabelle utenti";} ?>
    ora le tabelle sono state create correttamente ma quando vado per la registrazione e immetto tutti i dai: nome, cognome, indirizzo, occupazione, email, user, e pass; mi da il seguente errore:

    Registrazione Fallita a causa di un errore interno.

    come mai?

    ditemi se vi serve qualcosa per potermi aiutare.

    Grazie anticipatamente!

  2. #2

    Re: Registrazione utenti

    Originariamente inviato da lukezz


    ora le tabelle sono state create correttamente ma quando vado per la registrazione e immetto tutti i dai: nome, cognome, indirizzo, occupazione, email, user, e pass; mi da il seguente errore:

    Registrazione Fallita a causa di un errore interno.

    come mai?

    ditemi se vi serve qualcosa per potermi aiutare.

    Grazie anticipatamente!
    Chiaramente l'errore sarà nel codice che utilizzi per inserire i dati e non in quello che utilizzi per creare le tabelle che, se come dici sono state create, funziona perfettamente. posta il codice per l'inserimento.
    PHP LEARN - Guide, tutorial e articoli sempre aggiornati
    NUOVO: standardLib; il potente framework PHP é ora disponibile
    *******************************************
    Scarica oggi la tua copia di MtxEventManager

  3. #3
    Utente di HTML.it L'avatar di lukezz
    Registrato dal
    Feb 2010
    Messaggi
    494
    Ecco il form di registrazione:

    codice:
    <html> <head> <title>Modulo di registrazione</title> </head> <body> <form action="register.php" method="post"> <div align="center"> <table border="0" width="300"> 	<tr> 		<td>Nome:</td> 		<td><input type="text" name="name"></td> 	</tr> 	<tr> 		<td>Cognome:</td> 		<td><input type="text" name="surname"></td> 	</tr> 	<tr> 		<td>Indirizzo:</td> 		<td><input type="text" name="indirizzo"></td> 	</tr> 	<tr> 		<td>Occupazione</td> 		<td><input type="text" name="occupazione"></td> 	</tr> 	<tr> 		<td>Username:</td> 		<td><input type="text" name="username"></td> 	</tr> 	<tr> 		<td>Password:</td> 		<td><input type="password" name="password"></td> 	</tr> 	<tr> 		<td>Mail:</td> 		<td><input type="text" name="mail"></td> 	</tr> 	<tr> 		<td colspan="2" align="center"><input type="submit" name="action" value="Invia"></td> 	</tr> </table> </div> </form> </body> </html>
    E questo è il file register.php:

    Codice PHP:
    <html> <head> <style type="text/css">  </style> </head> <body> <?php include_once("include/config.php"); include_once("include/reg.lib.php");  if(isset($_POST['action']) and $_POST['action'] == 'Invia'){     $ret reg_check_data($_POST);     $status = ($ret === true) ? reg_register($_POST) : REG_ERRORS;          switch($status){         case REG_ERRORS:             ?>             <span class="style1">Sono stati rilevati i seguenti errori:</span>
                 <?php             foreach($ret as $error)                 printf("[b]%s[/b]: %s
    "
    $error[0], $error[1]);             ?>
                 Premere "indietro" per modificare i dati             <?php         break;         case REG_FAILED:             echo "Registrazione Fallita a causa di un errore interno.";         break;         case REG_SUCCESS:             echo "Registrazione avvenuta con successo.
                 Vi è stata inviata una email contente le istruzioni per confermare la registrazione."
    ;         break;     } } ?> </body> </html>

  4. #4
    Utente di HTML.it L'avatar di lukezz
    Registrato dal
    Feb 2010
    Messaggi
    494
    dimenticavo di dirvi che la guida mi dice di apportare delle modifiche alla tabella utenti in questo modo:

    codice:
    ALTER TABLE utenti ADD indirizzo VARCHAR( 100 ) NOT NULL, ADD occupazione VARCHAR( 100 ) NOT NULL, ADD temp SET( '0', '1' ) NOT NULL, ADD regdate VARCHAR( 11 ) NOT NULL, ADD uid VARCHAR( 32 ) NOT NULL;
    Ma non l'ho capito.

    Per favore ho bisogno del vostro aiuto

  5. #5
    Utente di HTML.it L'avatar di lukezz
    Registrato dal
    Feb 2010
    Messaggi
    494
    nessuno sa rispondermi? raga per favore è urgente!

  6. #6
    Utente di HTML.it L'avatar di lukezz
    Registrato dal
    Feb 2010
    Messaggi
    494
    Raga lavorandoci DA SOLO.. ho notato che nella creazione delle tabelle se vado ad aggiungere a questa:

    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,
    occupazione VARCHAR(100) NOT NULL,
    indirizzo VARCHAR(100) NOT NULL,
    mail VARCHAR (30) NOT NULL,
    temp SET( '0', '1' ) NOT NULL,
    regdate VARCHAR( 11 ) NOT NULL,
    PRIMARY KEY(id),
    INDEX(username, password)

    questo: uid VARCHAR( 32 ) NOT NULL; mi da l'errore della creazione table utenti. uid sarebbe la conferma di registrazione quindi l'errore penso sia questo.

    quindi come mai non mi fa mettere nella tabella uid VARCHAR( 32 ) NOT NULL;??

  7. #7
    Utente di HTML.it L'avatar di lukezz
    Registrato dal
    Feb 2010
    Messaggi
    494
    Allora sicuramente mi sono espresso male.. ricapitoliamo:

    Ho seguito questa guida per la registrazione utenti:http://php.html.it/articoli/leggi/90...tenti-con-php/

    Nella pagina 4 mi dice di aggiungere alla tabella questo:

    ALTER TABLE utenti
    ADD indirizzo VARCHAR( 100 ) NOT NULL,
    ADD occupazione VARCHAR( 100 ) NOT NULL,
    ADD temp SET( '0', '1' ) NOT NULL,
    ADD regdate VARCHAR( 11 ) NOT NULL,
    ADD uid VARCHAR( 32 ) NOT NULL;

    chiedendo una conferma al db:
    Codice PHP:
    if ($result2 == 1){echo "tabella utenti creata.";} else{echo "errore creazione tabelle utenti";} 
    mi da l'errore creazione tabelle utenti. il problrma è uid VARCHAR (32) NOT NULL; che dovrebbe contenere un indice univoco che servirà per la conferma della registrazione. Questo lo so xkè facendo delle prove ad uno ad uno l'unica volta che mi dava l'errore era quando nella lista utenti c'era lui.

    Questo è il primo problema.

    Il secondo problema (che secondo me è collegato a questo, posso anche sbagliarmi) è che quando vado a compilare i campi per la registrazione mi da il seguente errore:

    "Registrazione Fallita a causa di un errore interno."

    Qui sotto vi mostro registrati.php, register.php, config.php e reg.lib.php:

    REGISTRATI.PHP

    Codice PHP:
    <html>
    <
    head>
    <
    title>Modulo di registrazione</title>
    </
    head>
    <
    body>
    <
    form action="register.php" method="post">
    <
    div align="center">
    <
    table border="0" width="300">
        <
    tr>
            <
    td>Nome:</td>
            <
    td><input type="text" name="name"></td>
        </
    tr>
        <
    tr>
            <
    td>Cognome:</td>
            <
    td><input type="text" name="surname"></td>
        </
    tr>
        <
    tr>
            <
    td>Indirizzo:</td>
            <
    td><input type="text" name="indirizzo"></td>
        </
    tr>
        <
    tr>
            <
    td>Occupazione</td>
            <
    td><input type="text" name="occupazione"></td>
        </
    tr>
        <
    tr>
            <
    td>Username:</td>
            <
    td><input type="text" name="username"></td>
        </
    tr>
        <
    tr>
            <
    td>Password:</td>
            <
    td><input type="password" name="password"></td>
        </
    tr>
        <
    tr>
            <
    td>Mail:</td>
            <
    td><input type="text" name="mail"></td>
        </
    tr>
        <
    tr>
            <
    td colspan="2" align="center"><input type="submit" name="action" value="Invia"></td>
        </
    tr>
    </
    table>
    </
    div>
    </
    form>
    </
    body>
    </
    html
    REGISTER.PHP

    Codice PHP:
    <html>
    <head>
    <style type="text/css">
    <!--
    .style1 {
        color: #FF0000;
        font-weight: bold;
    }
    -->
    </style>
    </head>
    <body>
    <?php
    include_once("include/config.php");
    include_once(
    "include/reg.lib.php");

    if(isset(
    $_POST['action']) and $_POST['action'] == 'Invia'){
        
    $ret reg_check_data($_POST);
        
    $status = ($ret === true) ? reg_register($_POST) : REG_ERRORS;
        
        switch(
    $status){
            case 
    REG_ERRORS:
                
    ?>
                <span class="style1">Sono stati rilevati i seguenti errori:</span>

                <?php
                
    foreach($ret as $error)
                    
    printf("[b]%s[/b]: %s
    "
    $error[0], $error[1]);
                
    ?>

                Premere "indietro" per modificare i dati
                <?php
            
    break;
            case 
    REG_FAILED:
                echo 
    "Registrazione Fallita a causa di un errore interno.";
            break;
            case 
    REG_SUCCESS:
                echo 
    "Registrazione avvenuta con successo.

                Vi è stata inviata una email contente le istruzioni per confermare la registrazione."
    ;
            break;
        }
    }
    ?>
    </body>
    </html>
    CONFIG.PHP

    Codice PHP:
    <?php
    $_CONFIG
    ['host'] = "62.149.150.109";
    $_CONFIG['user'] = "Sql315514";
    $_CONFIG['pass'] = "51329d04";
    $_CONFIG['dbname'] = "Sql315514_1";

    $_CONFIG['table_sessioni'] = "sessioni";
    $_CONFIG['table_utenti'] = "utenti";

    $_CONFIG['expire'] = 60;
    $_CONFIG['regexpire'] = 24//in ore

    $_CONFIG['check_table'] = array(
        
    "username" => "check_username",
        
    "password" => "check_global",
        
    "name" => "check_global",
        
    "surname" => "check_global",
        
    "indirizzo" => "check_global",
        
    "occupazione" => "check_global",
        
    "mail" => "check_global"
    );

    function 
    check_username($value){
        global 
    $_CONFIG;
        
        
    $value trim($value);
        if(
    $value == "")
            return 
    "Il campo non può essere lasciato vuoto";
        
    $query mysql_query("
        SELECT id
        FROM "
    .$_CONFIG['table_utenti']."
        WHERE username='"
    .$value."'");
        if(
    mysql_num_rows($query) != 0)
            return 
    "Nome utente già utilizzato";
        
        return 
    true;
    }

    function 
    check_global($value){
        global 
    $_CONFIG;
        
        
    $value trim($value);
        if(
    $value == "")
            return 
    "Il campo non può essere lasciato vuoto";
        
        return 
    true;
    }


    //--------------
    define('AUTH_LOGGED'99);
    define('AUTH_NOT_LOGGED'100);

    define('AUTH_USE_COOKIE'101);
    define('AUTH_USE_LINK'103);
    define('AUTH_INVALID_PARAMS'104);
    define('AUTH_LOGEDD_IN'105);
    define('AUTH_FAILED'106);

    define('REG_ERRORS'107);
    define('REG_SUCCESS'108);
    define('REG_FAILED'109);

    $conn mysql_connect($_CONFIG['host'], $_CONFIG['user'], $_CONFIG['pass']) or die('Impossibile stabilire una connessione');
    mysql_select_db($_CONFIG['dbname']);
    ?>
    REG.LIB.PHP

    Codice PHP:
    <?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()){
            return 
    reg_send_confirmation_mail($data['mail'], "perri.filippo@live.it"$id);
        }else return 
    REG_FAILED;
    }

    function 
    reg_send_confirmation_mail($to$from$id){
        
    //invio la mail di conferma
        
    $msg "Per confermare l'avvenuta registrazione, clicckate il link seguente:
        [url]http://www.sistemagroup.eu/registrazione/confirm.php?id=[/url]"
    .$id."
        "
    ;
        return (
    mail($to"Conferma la registrazione"$msg"From: ".$from)) ? REG_SUCCESS REG_FAILED;
    }

    function 
    reg_clean_expired(){
        global 
    $_CONFIG;
        
        
    $query mysql_query("
        DELETE FROM "
    .$_CONFIG['table_utenti']."
        WHERE (regdate + "
    .($_CONFIG['regexpire'] * 60 60).") <= ".time()." and temp='1'");
    }

    function 
    reg_get_unique_id(){
        
    //restituisce un ID univoco per gestire la registrazione
        
    list($usec$sec) = explode(' 'microtime());
        
    mt_srand((float) $sec + ((float) $usec 100000));
        return 
    md5(uniqid(mt_rand(), true));
    }

    function 
    reg_check_data(&$data){
        global 
    $_CONFIG;
        
        
    $errors = array();
        
        foreach(
    $data as $field_name => $value){
            
    $func $_CONFIG['check_table'][$field_name];
            if(!
    is_null($func)){
                
    $ret $func($value);
                if(
    $ret !== true)
                    
    $errors[] = array($field_name$ret);
            }
        }
        
        return 
    count($errors) > $errors true;
    }

    function 
    reg_confirm($id){
        global 
    $_CONFIG;
        
        
    $query mysql_query("
        UPDATE "
    .$_CONFIG['table_utenti']."
        SET temp='0'
        WHERE uid='"
    .$id."'");
        
        return (
    mysql_affected_rows () != 0) ? REG_SUCCESS REG_FAILED;
    }
    ?>
    Ho sistemato il codice perchè in quel modo era illeggilbile.

  8. #8
    Utente di HTML.it L'avatar di lukezz
    Registrato dal
    Feb 2010
    Messaggi
    494
    Grazie per le risposte!

  9. #9
    Utente di HTML.it L'avatar di Virus_101
    Registrato dal
    Sep 2008
    Messaggi
    2,497
    Ue ora non ho molto tempo vedo magari stasera s eriesco ad avere 5 minuti.

    Cmq mi sa che ti stai incasinando abrega la vita da solo.

    io partirei innanzitutto da questa considerazione :

    create table users (

    id int auto_increment not null,
    ....
    );


    Cosi' crei la tabela correttamente nota la sequenza degli attributi sull'id.

    Per il resto spero di avere 2 secondi stasera.

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.