Pagina 1 di 4 1 2 3 ... ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 38

Discussione: Problema php/sql

  1. #1
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    71

    Problema php/sql

    quando registro i dati di un utente mi da questo errore qua :
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') VALUES ('43', '43', '24324', 'e10ad' at line 7

  2. #2
    Non conoscendo tutta la query, dirti dov'è l'errore è un pò difficile...

  3. #3
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    71
    cosa ti devo postare?

  4. #4
    La query completa...

  5. #5
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    71
    questo è il codice che salva i dati nel db
    Codice PHP:
    <?php
    require('connessionedb.php');
    $user mysql_real_escape_string($_POST['user']);
    $user_mail $_POST['user'];
    $pass mysql_real_escape_string(md5($_POST['pass']));
    $pass_mail $_POST['pass'];
    $firstname mysql_real_escape_string($_POST['firstname']);
    $lastname =  mysql_real_escape_string($_POST['lastname']);
    $sesso mysql_real_escape_string($_POST['sesso']);
    $day mysql_real_escape_string(md5($_POST['day']));
    $month mysql_real_escape_string($_POST['month']);
    $year =  mysql_real_escape_string($_POST['year']);
    $country =  mysql_real_escape_string($_POST['country']);

    //$connection = mysql_connect("localhost", "username", "password");
    //mysql_select_db("db2", $connection);

    mysql_query("insert into 
    "
    .$db_tabella."(sesso,day,month,year,country) values('".$sesso."', '".$day."', '".$month."', '".$year."', '".$country."')");  

    $query "SELECT * FROM user " .
              
    "WHERE user_username = '$user' " .
              
    "OR user_email = '$pass' ";
    $result mysql_query($query) or die (mysql_error());
    if (
    mysql_num_rows($result) != 0)
    {
    while (
    $row mysql_fetch_array($result))
    {
       if (
    $row['user_username'] == $user)
      {
       echo 
    "

    "
    ;
       echo 
    "L'username, [b]" $row['user_username'] . "[/b] è già in uso da un altro utente, scegliere uno diverso";
       echo 
    "</p>";
      }
      if (
    $row['user_email'] == $_POST['email'])
      {
       echo 
    "

    "
    ;
       echo 
    "La casella E-mail, [b]" $row['user_email'] . "[/b] è già presente nel Data Base, scegliere una diversa";
       echo 
    "</p>";
      }
    }
    echo 
    "

    "
    ;
    echo 
    "<a href=\"registrazione.php\">";
    echo 
    "<<< Clicca qui per ritornare alla pagina precedente";
    echo 
    "</a>";
    echo 
    "</p>";
    exit();
    }
    else
    {
       switch (
    $_GET['action'])
       {
         case 
    "add":
         switch (
    $_GET['type'])
         {
          case 
    "user":
          
    $sql "INSERT INTO user
                   (user_firstname,
            user_lastname,
             user_username,
            user_password,
            user_email,
            )
          VALUES
            ('
    $firstname',
            '
    $lastname',
            '
    $user',
            '
    $pass',
            '" 
    $_POST['email'] . "')";
           
    $users mysql_query($sql) or die(mysql_error());
           
    $id mysql_insert_id();
           break;
         }
        break;
       }
    }
    $temp gettimeofday();
    $msec = (int) $temp["usec"];
    $msgid md5(time() . $msec);
    $ins "INSERT INTO confirm
           (confirm_validator,
        confirm_userid)
         VALUES
       ('
    $msgid',
        '
    $id')";
    $res mysql_query($ins) or die(mysql_error());
    ?>
    <html>
    <head>
    <title>Inserimento dati</title>
    </head>
    <body>
    <?php
    $to 
    $_POST["email"];
    $toname $_POST["firstname"];
    $subject "Completa la tua registrazione";

    $boundary "==MP_Bound_xyccr948x==";
    $headers "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: multipart/alternative; boundary=\"$boundary\"\r\n";
    $headers .= "From: mailda [email]inserire@tuoserver.it[/email]\r\n";
    $html_msg "<center>";
    $html_msg .= "<table width=\"500\" border=0 cellpadding=\"4\">";
    $html_msg .= "<tr><td align=\"center\">";
    $html_msg .= "</td></tr>";
    $html_msg .= "<tr><td>Questi sono i dati della tua registrazione:";
    $html_msg .= "</td></tr><tr><td>Username: <font color=\"red\">" $user_mail "</font>";
    $html_msg .= "</td></tr><tr><td>Password: <font color=\"red\">" $pass_mail "</font>";
    $html_msg .= "</td></tr><tr><td align=\"center\">";
    $html_msg .= "</td></tr></table></center>";
    $confirmmessage "Salve " $toname ",\n\n";
    $confirmmessage .= "per completare la tua registrazione devi cliccare sul link sottostante:\n\n";
    $confirmmessage .= $html_msg "\n\n";
    $confirmmessage .= "<a href=\"http://localhost/percorso pagina confirm_reg.php" .
      
    "?id=$msgid\">Clicca qui per confermare la tua registrazione</a>";
    $message "This is a Multipart Message in MIME format\n";
    $message .= "--$boundary\n";
    $message .= "Content-type: text/html; charset=iso-8859-1\n";
    $message .= "Content-Transfer-Encoding: 7bit\n\n";
    $message .= $confirmmessage "\n";
    $message .= "--$boundary--";
    $mailsent mail($to$subject$message$headers);
    if (
    $mailsent)
    {
      echo 
    "Salve" .  $toname ",
    "
    ;
      echo 
    "Un messaggio è stato inviato all'indirizzo [b]" $to "[/b] da te fornito.

    "
    ;
      echo 
    "IMPORTANTE:
    "
    ;
      echo 
    "Per completare la registrazione al sito devi aprire la tua casella e-mail, leggere il messaggio di conferma e cliccare sul link che troverai all'interno.

    "
    ;
    } else {
      echo 
    "Errore durante l'invio dell'e-mail.";
    }
    ?>
    </body>
    </html>

  6. #6
    Il problema non è conoscere la tua query, ma la struttura della tabella.
    Così ad occhio, guardando semplicemente il tuo codice di errore, mi viene da pensare che passi dei numeri tra apici, per cui in formato stringa, cercando di metterli dentro colonne che si aspettano degli INT, per cui ti viene restituito il messaggio di errore.

    Prova a togliere gli apici da tutti i valori numerici e vedi se la query funziona.

    <ALCIO />
    Per cortesia: no PVT Tecnici
    ******* LINKS *******
    SRL
    MetalWave

  7. #7
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    71
    ok risolto quel problema ora me ne da un altro questo qua ...

    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\registrazione_e_gestione_utenti\data_i nsert.php on line 125

    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\registrazione_e_gestione_utenti\data_i nsert.php on line 126

    Codice PHP:
    <?php
    require('connessionedb.php');
    $user mysql_real_escape_string($_POST['user']);
    $user_mail $_POST['user'];
    $pass mysql_real_escape_string($_POST['pass']); 
    $pass_mail $_POST['pass'];
    $firstname mysql_real_escape_string($_POST['firstname']);
    $lastname =  mysql_real_escape_string($_POST['lastname']);
    $sesso mysql_real_escape_string($_POST['sesso']);
    $day mysql_real_escape_string($_POST['day']);
    $month mysql_real_escape_string($_POST['month']);
    $year =  mysql_real_escape_string($_POST['year']);
    $country =  mysql_real_escape_string($_POST['country']);
    $query "SELECT * FROM user " .
              
    "WHERE user_username = '$user' " .
              
    "OR user_email = '$pass' ";
    $result mysql_query($query) or die (mysql_error());
    if (
    mysql_num_rows($result) != 0)
    {
    while (
    $row mysql_fetch_array($result))
    {
       if (
    $row['user_username'] == $user)
      {
       echo 
    "

    "
    ;
       echo 
    "L'username, [b]" $row['user_username'] . "[/b] è già in uso da un altro utente, scegliere uno diverso";
       echo 
    "</p>";
      }
      if (
    $row['user_email'] == $_POST['email'])
      {
       echo 
    "

    "
    ;
       echo 
    "La casella E-mail, [b]" $row['user_email'] . "[/b] è già presente nel Data Base, scegliere una diversa";
       echo 
    "</p>";
      }
    }
    echo 
    "

    "
    ;
    echo 
    "<a href=\"registrazione.php\">";
    echo 
    "<<< Clicca qui per ritornare alla pagina precedente";
    echo 
    "</a>";
    echo 
    "</p>";
    exit();
    }
    else
    {
       switch (
    $_GET['action'])
       {
         case 
    "add":
         switch (
    $_GET['type'])
         {
          case 
    "user":
          
    $sql "INSERT INTO user
                   (user_firstname,
            user_lastname,
             user_username,
            user_password,
            sesso,
            day,
            month,
            year,
            country,
            user_email)
          VALUES
            ('
    $firstname',
            '
    $lastname',
            '
    $user',
            '
    $pass',
            '
    $sesso',
            '
    $day',
            '
    $month',
            '
    $year',
            '
    $country',
            '" 
    $_POST['email'] . "')";
           
    $users mysql_query($sql) or die(mysql_error());
           
    $id mysql_insert_id(); 
           break;
         }
        break;
       }
    }
    $temp gettimeofday();
    $msec = (int) $temp["usec"];
    $msgid md5(time() . $msec);
    $ins "INSERT INTO confirm
           (confirm_validator,
        confirm_userid)
         VALUES
       ('
    $msgid',
        '
    $id')";
    $res mysql_query($ins) or die(mysql_error());
    ?>
    <html>
    <head>
    <title>Inserimento dati</title>
    </head>
    <body>
    <?php
    $to 
    $_POST["email"];
    $toname $_POST["firstname"];
    $subject "Completa la tua registrazione";

    $boundary "==MP_Bound_xyccr948x==";
    $headers "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: multipart/alternative; boundary=\"$boundary\"\r\n";
    $headers .= "From: mailda [email]inserire@tuoserver.it[/email]\r\n"//l'indirizzo email
    $html_msg "<center>";
    $html_msg .= "<table width=\"500\" border=0 cellpadding=\"4\">";
    $html_msg .= "<tr><td align=\"center\">";
    $html_msg .= "</td></tr>";
    $html_msg .= "<tr><td>Questi sono i dati della tua registrazione:";
    $html_msg .= "</td></tr><tr><td>Username: <font color=\"red\">" $user_mail "</font>";
    $html_msg .= "</td></tr><tr><td>Password: <font color=\"red\">" $pass_mail "</font>";
    $html_msg .= "</td></tr><tr><td align=\"center\">";
    $html_msg .= "</td></tr></table></center>";
    $confirmmessage "Salve " $toname ",\n\n";
    $confirmmessage .= "per completare la tua registrazione devi cliccare sul link sottostante:\n\n";
    $confirmmessage .= $html_msg "\n\n";
    // inserire il percorso esatto che porta alla nostra pagina confirm_reg.php
    $confirmmessage .= "<a href=\"http://localhost/percorso pagina confirm_reg.php" .
      
    "?id=$msgid\">Clicca qui per confermare la tua registrazione</a>";
    $message "This is a Multipart Message in MIME format\n";
    $message .= "--$boundary\n";
    $message .= "Content-type: text/html; charset=iso-8859-1\n";
    $message .= "Content-Transfer-Encoding: 7bit\n\n";
    $message .= $confirmmessage "\n";
    $message .= "--$boundary--";
    mail($to$subject$message$headers);// LINEA 125
    if (!mail($to$subject$message$headers))//LINEA 126
    {
      echo 
    "Salve" .  $toname ",
    "
    ;
      echo 
    "Un messaggio è stato inviato all'indirizzo [b]" $to "[/b] da te fornito.

    "
    ;
      echo 
    "IMPORTANTE:
    "
    ;
      echo 
    "Per completare la registrazione al sito devi aprire la tua casella e-mail, leggere il messaggio di conferma e cliccare sul link che troverai all'interno.

    "
    ;
    } else {
      echo 
    "Errore durante l'invio dell'e-mail.";
    }
    ?>
    </body>
    </html>
    neller righe 125 e 126
    è meglio tenere quel codice o questo :
    Codice PHP:
    $mailsent mail($to$subject$message$headers);
    if (
    $mailsent
    cmq in entrabi i casi mi da errore

  8. #8
    Originariamente inviato da rollone
    ok risolto quel problema ora me ne da un altro questo qua ...

    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\registrazione_e_gestione_utenti\data_i nsert.php on line 125

    Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\registrazione_e_gestione_utenti\data_i nsert.php on line 126
    Ciao,
    non dipende da cosa scrivi, non hai un mailserver sul tuo localhost.

    Se lo provi su un dominio registrato, sicuramente va.

    --Cosimo
    --Cosimo
    MAIL: cosimo.g18@gmail.com

  9. #9
    Se stai effettuando prove in locale, devi fermare il server, e modificare il PHP.INI.
    Devi inserire i riferimenti al server SMTP ed all'indirizzo email che usi come predefinito, cioè i parametri della casella email che hai con il tuo ISP.

    <ALCIO />
    Per cortesia: no PVT Tecnici
    ******* LINKS *******
    SRL
    MetalWave

  10. #10
    Utente di HTML.it
    Registrato dal
    Jul 2009
    Messaggi
    71
    si sto provando in locale xò non so come impostare il file per il locale qualcuno mi aiuta?

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.