Pagina 1 di 3 1 2 3 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 26
  1. #1
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560

    controllo email già esistente nel db

    Non capisco perchè con questo codice quando inserisco qualsiasi email al momento della registrazione mi dice che l'email già esiste, dov'è l'errore? non lo trovo

    Codice PHP:
    //Verifico la presenza dell'e-mail nel database
    $query "SELECT * FROM members WHERE email='email'";
    $result mysql_query($sql);
    $verify mysql_fetch_row($result);

    if(
    count($verify))//Verifico se l'e-mail esiste nel database almeno una volta
    {
    echo 
    "Impossibile completare la registarzione: qualcuno ha già efettuato la registarzione con l'e-mail  '$email'; utilizzane un'altra!";
    }else{
    //altrimenti eseguo la query 


    codice completo

    Codice PHP:
    <?php
    mysql_select_db
    ($database_myconn$myconn);
    $query_state "SELECT * FROM `state` ORDER BY title ASC";
    $state mysql_query($query_state$myconn) or die(mysql_error());
    $row_state mysql_fetch_assoc($state);
    $totalRows_state mysql_num_rows($state);

    $settings mysql_fetch_assoc(mysql_query('select * from settings'));

    function 
    GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
    {
      
    $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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;
    }

    $editFormAction $_SERVER['PHP_SELF'];
    if (isset(
    $_SERVER['QUERY_STRING'])) {
      
    $editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
    }

    if ((isset(
    $_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

        
    //validate
        
    $error "";
        if(
    $_REQUEST['name'] == "")
            
    $error.= "Inserisci Nome,
    "
    ;
        if(
    $_REQUEST['address'] =="")
            
    $error.= "Inserisci Indirizzo,
    "
    ;
        if(
    $_REQUEST['city'] =="")
            
    $error.="Inserisci Città,
    "
    ;
        if(
    $_REQUEST['state'] =="")
            
    $error.="Inserisci Regione,
    "
    ;
        if(
    $_REQUEST['zip'] =="")
            
    $error.="Inserisci CAP,
    "
    ;
        if(
    $_REQUEST['email'] =="")
            
    $error.="Inserisci Email,
    "
    ;
        if(
    $_REQUEST['phone']=="")
            
    $error.="Inserisci Telefono,
    "
    ;
        if(
    $error != ""){
            echo 
    "<div class='free'><p class='rightTxt1'><button onClick='history.back()'>Indietro</button></p><blockquote>".$error."</blockquote></div>";
            die();
        }
      
    $password rand(9898,9898998);
      
    //Verifico la presenza dell'e-mail nel database
    $query "SELECT * FROM members WHERE email='email'";
    $result mysql_query($sql);
    $verify mysql_fetch_row($result);

    if(
    count($verify))//Verifico se l'e-mail esiste nel database almeno una volta
    {
    echo 
    "Impossibile completare la registarzione: qualcuno ha già efettuato la registarzione con l'e-mail  '$email'; utilizzane un'altra!";
    }else{
    //altrimenti eseguo la query
      
      //send member information
      
    $message 
    '
    Thanks for registering.

    Please keep the following for your records:

    Username: '
    .$_REQUEST['email'].'
    Password: '
    .$password;
     
    //mail member
      
    @mail($_REQUEST['email'],'Member Registration',$message,'From:'.$settings['email']);
      
    $mailmessage '<div align=center class="pageSubTitle">Username and Password sent to '.$_REQUEST['email'].'</div>';
      @
    mail($settings['email'],'How did you hear about us',$_REQUEST['hear_about'],'From:'.$settings['email']);
      
    $insertSQL sprintf("INSERT INTO members (name, address, city, `state`, zip, active, email, password, phone) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
                           
    GetSQLValueString($_POST['name'], "text"),
                           
    GetSQLValueString($_POST['address'], "text"),
                           
    GetSQLValueString($_POST['city'], "text"),
                           
    GetSQLValueString($_POST['state'], "text"),
                           
    GetSQLValueString($_POST['zip'], "text"),
                           
    GetSQLValueString($_POST['active'], "text"),
                           
    GetSQLValueString($_POST['email'], "text"),
                           
    GetSQLValueString(md5($password), "text"),
                           
    GetSQLValueString($_POST['phone'], "text"));

      
    mysql_select_db($database_myconn$myconn);
      
    $Result1 mysql_query($insertSQL$myconn) or die(mysql_error());
        
      echo 
    "<h3>You are now registered, check your email for username and password</h3> [url='login.php']Sign In[/url]";
      
    $message =
      
    'A new user has signed up to '.$settings['domain'].'
      
      Member Info: 
      '
    .$_REQUEST['name'].'
      '
    .$_REQUEST['phone'].'
      '
    .$_REQUEST['email'].'
      
      '
    ;
      
    mail($settings['email'],"New Registered User",$message,"FROM:".$settings['email']);
    }
    }
    ?>

  2. #2
    if(count($verify))

    CREDO che con tale condizioni verifichi solo se il risultato di count è vero... anche se ==0 è cmq vero.
    Modifica così:

    if(count($verify)>=1)

    Inoltre ti conviene utilizzare mysql_num_row senza utilizzare count

    if(mysql_num_row($result)>=1)

  3. #3
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    non funziona neanche così...

  4. #4
    allora dipende da altro... fai così e verifica la corretta sintassi della query

    $result = mysql_query($sql) or die ("errore nella query o nella connessione");

  5. #5
    Utente di HTML.it
    Registrato dal
    Nov 2008
    Messaggi
    539
    Codice PHP:
    $query "SELECT * FROM members WHERE email='email'";
    $result mysql_query($sql); 
    fai una where su 'email' quando dovresti farla su $_POST['email'];
    fai mysql_query($sql) ma $sql non esiste: dovrebbe essere mysql_query($query).

  6. #6
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Codice PHP:
    //Verifico la presenza dell'e-mail nel database
    $query "SELECT * FROM members WHERE email='email'";
    $result mysql_query($sql) or die ("errore nella query o nella connessione");
    $verify mysql_fetch_row($result); 
    metto così?

    non mi restituisce nulla così..

  7. #7
    Utente di HTML.it L'avatar di Lino80
    Registrato dal
    Oct 2005
    Messaggi
    1,560
    Codice PHP:
    $query "SELECT * FROM members WHERE email='$_POST['email']'"
    così non è corretto vero?

  8. #8
    Utente di HTML.it
    Registrato dal
    Nov 2008
    Messaggi
    539
    Codice PHP:
    $query "SELECT * FROM members WHERE email='" $_POST['email'] . "'"
    ma ti conviene fare dei controlli preventivi su $_POST['email'] per evitare intrusioni nel db...

  9. #9
    freeman ha ragione

    Poi soprattutto l'email ha un controllo stra-ultra-mega-famoso con le espressioni regolari...
    Codice PHP:
    function validate_email($email)
        {
        if (
    preg_match('/^[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/',$email))
            {
            return 
    $email;
            }
        return 
    FALSE;
        }

    $email validate_email($_POST['email']); 
    Verifica il corretto funzionamente dato che alle volte il forum si mangia qualche slash (e cmq puoi cercare con google "php validate email regex" e ne trovi a bizzeffe...)

  10. #10
    Utente di HTML.it
    Registrato dal
    Nov 2008
    Messaggi
    539
    e correggi questo

    Codice PHP:
    $result mysql_query($sql); 
    con

    Codice PHP:
    $result mysql_query($query); 

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.