• User Attivo

    errore di sintassi

    raga qualcuno puo' aiutarmi? ci sto diventando scemo, ho aggiunto solo qualcosa e mi da
    Errore di sintassi nella query SQL vicino a 'add ,liv ,data_ass ,cod_qual ,altri_dati_dip1 ,altri_dati_dip2 ,altr' linea 1.

    Nella query ho messo $anag = mysql_query($q) or die (mysql_error());
    ma che vuol dire linea 1. Non riesco a trovare l'errore... eppure ho solo aggiunto dei campi....

    eppure andava prima....

    questa era la vecchia query:

    [PHP]$q = "insert into anag_dip (";
    $q .= " id_utente";
    $q .= " ,id_azienda";
    $q .= " ,cognome";
    $q .= " ,nome";
    $q .= " ,data_nascita";
    $q .= " ,citta_nascita";
    $q .= " ,codice_fiscale";
    $q .= " ,citta_residenza";
    $q .= " ,indirizzo";
    $q .= " ,cap";
    $q .= " ,non_so";
    $q .= " ,non_so2";
    $q .= " ,non_so3";

    $q .= " ,altri_dati_dip1";
    $q .= " ,altri_dati_dip2";
    $q .= " ,altri_dati_dip3";
    $q .= " ,altri_dati_dip4";
    $q .= " ,altri_dati_dip5";
    $q .= " ,altri_dati_dip6";
    $q .= " ,altri_dati_dip7";
    $q .= " ,altri_dati_dip8";
    $q .= " ,altri_dati_dip9";
    $q .= " ,altri_dati_dip10";
    $q .= " ,altri_dati_dip11";
    $q .= " ,altri_dati_dip12";
    $q .= " ,altri_dati_dip13";

    $q .= " ) values (";
    $q .= " (SELECT user_id FROM tbl_users WHERE user_name = '" . $_SESSION['logged'][0] . "')";
    $q .= " ,'" . $_POST['dittas'] . "'";
    $q .= " ,'" . addslashes(trim($_POST['cognome'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['nome'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['data_nascita'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['citta_nascita'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['codice_fiscale'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['citta_residenza'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['indirizzo'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['cap'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['non_so'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['non_so2'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['non_so3'])) . "'";

    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip1'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip2'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip3'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip4'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip5'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip6'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip7'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip8'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip9'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip10'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip11'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip12'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip13'])) . "'";

    $q .= " )";

    $anag = mysql_query($q);
    [/PHP]

    questa è la nuova:

    [PHP]
    $q = "insert into anag_dip (";
    $q .= " id_utente";
    $q .= " ,id_azienda";
    $q .= " ,cognome";
    $q .= " ,nome";
    $q .= " ,data_nascita";
    $q .= " ,citta_nascita";
    $q .= " ,codice_fiscale";
    $q .= " ,citta_residenza";
    $q .= " ,indirizzo";
    $q .= " ,cap";

    $q .= " ,stato_civile";//nuovo campo
    $q .= " ,stato_dip";//nuovo campo
    $q .= " ,qualifica";//nuovo campo
    $q .= " ,tratt_irpef";//nuovo campo
    $q .= " ,part_full";//nuovo campo
    $q .= " ,t_det_i";//nuovo campo
    $q .= " ,pos_inps";//nuovo campo
    $q .= " ,matr";//nuovo campo
    $q .= " ,add";//nuovo campo
    $q .= " ,liv";//nuovo campo
    $q .= " ,data_ass";//nuovo campo
    $q .= " ,cod_qual";//nuovo campo

    $q .= " ,altri_dati_dip1";
    $q .= " ,altri_dati_dip2";
    $q .= " ,altri_dati_dip3";
    $q .= " ,altri_dati_dip4";
    $q .= " ,altri_dati_dip5";
    $q .= " ,altri_dati_dip6";
    $q .= " ,altri_dati_dip7";
    $q .= " ,altri_dati_dip8";
    $q .= " ,altri_dati_dip9";
    $q .= " ,altri_dati_dip10";
    $q .= " ,altri_dati_dip11";
    $q .= " ,altri_dati_dip12";
    $q .= " ,altri_dati_dip13";

    $q .= " ) values (";
    $q .= " (SELECT user_id FROM tbl_users WHERE user_name = '" . $_SESSION['logged'][0] . "')";
    $q .= " ,'" . $_POST['dittas'] . "'";
    $q .= " ,'" . addslashes(trim($_POST['cognome'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['nome'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['data_nascita'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['citta_nascita'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['codice_fiscale'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['citta_residenza'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['indirizzo'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['cap'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['stato_civile'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['stato_dip'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['qualifica'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['tratt_irpef'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['part_full'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['t_det_i'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['pos_inps'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['matr'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['add'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['liv'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['data_ass'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['cod_qual'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip1'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip2'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip3'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip4'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip5'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip6'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip7'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip8'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip9'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip10'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip11'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip12'])) . "'";
    $q .= " ,'" . addslashes(trim($_POST['altri_dati_dip13'])) . "'";

    $q .= " )";

    $anag = mysql_query($q) or die (mysql_error());
    [/PHP]

    eppure nel database i campi sono tutti inseriti


  • ModSenior

    Stai mischiando insert e select O.o
    ti consiglio di rivedere il funzionamento di entrambi...


  • User Attivo

    @Thedarkita said:

    Stai mischiando insert e select O.o
    ti consiglio di rivedere il funzionamento di entrambi...

    Grazie, il problema era nel nome della variabile che avevo stabilito: "add".
    Andava messo tra apici altrimenti faceva casino con mysql...
    Ho cambiato nome, ora va...anche se devo capire bene il problema...
    Grazie comunque... Ciao