Visualizzazione dei risultati da 1 a 6 su 6
  1. #1

    Insert che crea due record anzichè uno solo

    Ho un form che una volta compilato passa i dati ad una pagina che li inserisce nel db.
    Il problema è che anzichè agigungere un solo record con i dati ricevuti dal form, ne inserisce due identici.
    Qui il codice di inserimento:
    codice:
    $action = $_GET['action'];
    
    switch ($action){
    
    case 1: 				#LA VARIABILE CHIEDE DI INSERIRE I DATI NEL DB
      $adm_nome 		= $_POST['adm_nome'];
      $adm_username = $_POST['adm_username'];
      $adm_psw 			= $_POST['adm_psw'];
      $adm_type 		= $_POST['adm_type'];
      $status 			= $_POST['status'];
      
      include("connesisone_db.php");
      
      $insert_admin = "INSERT INTO d_admin (adm_nome, adm_username, adm_psw, adm_type, status) VALUES ('" . $adm_nome . "', '" . $adm_username . "', '" . $adm_psw . "', '" . $adm_type . "', '" . $status . "')";
      
      mysql_query($insert_admin,$conn);
      
      mysql_close($conn);
      
      print ("<h2><img src=\"../images/info.gif\" alt=\"\" />DATI AGGIUNTI CORRETTAMENTE
    
    ");
    	print ("<a href=\"new_admin.php\">Aggiungi</a> un'altro admin
    
    <a href=\"../main.php\">Home</a></h2>");
    
    	break;
    }
    Io non vedo errori nel codice. Sta di fatto che vengono creati due record identici.
    Avete idea del come mai?

    Thanks

  2. #2
    Nessuno che sa aiutarmi?

  3. #3
    giusto per curiosità metti un if al posto dello switch

  4. #4
    Utente di HTML.it
    Registrato dal
    Aug 2002
    Messaggi
    8,013
    non è che per caso hai un submit "duplicato"?
    Posta un po' la pagina con il form
    <´¯)(¯`¤._)(¯`»ANDREA«´¯)(_.¤´¯)(¯`>
    "The answer to your question is: welcome to tomorrow"

  5. #5
    Codice del form:
    Codice PHP:
    <form action="esito_action.php?action=1" method="post">  
    <
    table class="form">
    <
    tr>
    <
    td class="form" width="100">NOME</td>
    <
    td class="dati"><input type="text" name="adm_nome" size="20"></td>
    </
    tr>
    <
    tr>
    <
    td class="form" width="100">USERNAME</td>
    <
    td class="dati"><input type="text" name="adm_username" size="20"></td>
    </
    tr>
    <
    tr>
    <
    td class="form" width="100">PASSWORD</td>
    <
    td class="dati"><input type="text" name="adm_psw" size="20"></td>
    </
    tr>
    <
    tr>
    <
    td class="form" width="100">TIPO</td>
    <
    td class="dati"><select name="adm_type">
    <
    option value="1" selected="selected">Amministratore</option>
    <
    option value="2">Controllore</option>
    </
    select></td>
    </
    tr>
    <
    tr>
    <
    td class="form" width="100">STATUS</td>
    <
    td class="dati"><select name="status">
    <
    option value="1" selected="selected">Attivo</option>
    <
    option value="0">Disattivo</option>
    </
    select></td>
    </
    tr>
    </
    table>
    <
    table>
    <
    tr>
    <
    td><input type="submit" class="submit" value="AGGIUNGI"><input type="reset" class="submit" value="CANCELLA"></td>
    </
    tr>
    </
    table
    Ma non saprei cosa intendi per form duplicato .

    @SuperSavio: ora provo con l'if.

  6. #6
    Con l'if funziona

    Sarebbe interessante capire il perchè.

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.