Visualizzazione dei risultati da 1 a 4 su 4
  1. #1
    Utente di HTML.it
    Registrato dal
    Jan 2006
    Messaggi
    17

    mysql insermento automatico di piu record

    Ciao,
    non riesco ad inserire automaticamente piu record in una tabella. questo è il mio script



    $filex = $allItems[$y]['LINK'];
    $newfile = $allItems[$y]['TITLE'].'.torrent';
    $newfilex = $allItems[$y]['TITLE'].'.torrent';

    $db = mysql_connect($db_host, $db_user, $db_password);
    if ($db == FALSE)
    die ("Errore nella connessione. Verificare i parametri nel file conn.php");
    mysql_select_db($db_name, $db)
    or die ("Errore nella selezione del database. Verificare i parametri nel file connphp");

    //inserimento dei dati nel db
    $query = "INSERT INTO torrent_torrents (filename) VALUES ('$newfilex')";


    if (mysql_query($query, $db))
    echo "
    L'installazione è stata eseguita correttamente";
    else
    echo "
    Errore durante l'installazione". mysql_error();
    mysql_close($db);

    IN PRATICA DOVREBBE INSERIRE PIU RECORD NELLA TABELLA TORRENTS_TORRENTS, MA MI DA QUESTO ERRORE
    Errore durante l'installazioneDuplicate entry '' for key 2
    PROBABILMENTE PERCHè PRENDE PIU FILE E LI METTE NELLA STESSA LINEA, DOVREI INSERIRE LE INFORMAZIONI IN PIU LINEE, MAGARI CON UNA FUNZIONE DI AUTO INCREMENT DI CUI LA TABELLA TORRENTS_TORRENTS HA L'ID AUTO INCREMENT, LA VARIABILE NEWFILEX RESTITUISCE I NOMI DI 20 FILE.
    COME DOVREI METTERE IN QUESTO CASO LA QUERY?

  2. #2
    Utente di HTML.it
    Registrato dal
    Mar 2004
    Messaggi
    1,141
    Nella tua tabella hai un id autoincrement per caso, perchè allora dovresti fare:
    $query = "INSERT INTO torrent_torrents (id,filename) VALUES ('','$newfilex')";

    oppure l'rrore potrebbe essere dovuto la fatto che hai messo in campo 'filename' come primary key oppure l'hai messo UNIQUE (nel qual caso, non accetta più record con lo stesso valore, quindi non potrai avere due 'pippo.txt' nel DB, ma solo uno).

    Se non è uno di questi casi, non saprei...

    ciao

  3. #3
    Utente di HTML.it
    Registrato dal
    Jan 2006
    Messaggi
    17
    HAI RAGIONE SEI GRANDE, CREDO CHE FILENAME SIA UN CAMPO UNIQUE!
    E HAI RAGIONE CHE HO UN CAMPO AUTO INCREMENT CHE è NOMINATO ID
    HO PROVATO COME HAI DETTO TU
    $query = "INSERT INTO torrent_torrents (id,filename) VALUES ('','$newfilex')";

    MA RESTITUISCE SEMPRE LO STESSO ERRORE

    [0]: Link : http://static.thepiratebay.org/downl...48.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [1]: Link : http://static.thepiratebay.org/downl...46.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [2]: Link : http://static.thepiratebay.org/downl...45.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [3]: Link : http://static.thepiratebay.org/downl...44.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [4]: Link : http://static.thepiratebay.org/downl...32043.torrent/[GP2X]_Documental__Mas_Alla_de_lo_Humano_(1-2)._taromaru.3432043.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [5]: Link : http://static.thepiratebay.org/downl...42.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [6]: Link : http://static.thepiratebay.org/downl...41.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [7]: Link : http://static.thepiratebay.org/downl...40.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [8]: Link : http://static.thepiratebay.org/downl...re_del_tiempo.[wWw.VicioDivX.Tk].3432039.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [9]: Link : http://static.thepiratebay.org/downl...38.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [10]: Link : http://static.thepiratebay.org/downl...37.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [11]: Link : http://static.thepiratebay.org/downl...36.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [12]: Link : http://static.thepiratebay.org/downl...35.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [13]: Link : http://static.thepiratebay.org/downl...33.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [14]: Link : http://static.thepiratebay.org/downl...32.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [15]: Link : http://static.thepiratebay.org/downl...31.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [16]: Link : http://static.thepiratebay.org/downl...30.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [17]: Link : http://static.thepiratebay.org/downl...29.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [18]: Link : http://static.thepiratebay.org/downl...28.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2 [19]: Link : http://static.thepiratebay.org/downl...27.TPB.torrent
    Errore durante l'installazioneDuplicate entry '' for key 2


    MI CREA SOLO UNA LINEA CON SOLO IL PRIMO FILENAME

  4. #4
    Utente di HTML.it
    Registrato dal
    Mar 2004
    Messaggi
    1,141
    Bhè, se il campo filename è UNIQUE è logico che ti restituisca quell'errore.
    Le cose sono 2:
    1- o lo lasci UNIQUE, fai il controllo sul nome e se esiste già lo cambi in qualche modo

    2- modifichi qyuel campo togliendogli l'attributo unique

    vedi tu...

    ciao

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.