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

    Semplice problema post da multiple select

    Buonasera a tutti,
    ho un semplice select multiplo in un form:
    Codice HTML:

    codice:
    <select multiple="multiple" id="nome"> ecc. ecc..
    con un js che mi prende i dati
    Codice:

    codice:
    function addRecord() {     var term_nome = $('#nome').val();        //Storing the value of textbox into a variable          if(term_nome == '')                        //Checking for NULL     {         $('#propspectDiv').html('Inserire i dati obbligatori');    //Prints the progress text into our Progress DIV         return;     }     else{         $('#propspectDiv').removeClass('error');                                     //Removing the error class from the progress DIV         $('#propspectDiv').html('Attendere prego...
    [img]ajax.gif[/img]');    //Prints the progress text into our Progress DIV                  $.ajax({                 url : 'data.php',                     //Declaration of file, in which we will send the data                 data:{                     "nome" : term_nome,                //we are passing the nome value in URL                 },                 success : function(data){                     window.setTimeout(function(){                         $('#propspectDiv').html('Grazie, la missione è stata registrata'); //Prints the progress text into our Progress DIV                         $('#data').css("display","block");  //Changes the style of table from display:none to display:block                         $('#data').html(data);                //Prints the data into the table                     }, 1500);                 }             });     } }
    e un php che mi salva su db mysql
    Codice PHP:

    Codice PHP:
    <?php $nome $_REQUEST['nome'];  $con mysql_connect("localhost","root","");  mysql_select_db("missioni"$con);  $sql 'INSERT INTO `data` (`ID`, `nome`) VALUES (NULL,"'.$nome.'")';  if (!mysql_query($sql,$con))   {   die('Errore: ' mysql_error());   }   else{     $sqlnew 'SELECT * from missioni ORDER BY ID desc LIMIT 1;';     $res mysql_query($sqlnew);     while($row mysql_fetch_array($res))     {         echo '          <p class="lead text-success">'.$row['nome'].'</p>          ';     }   }  mysql_close($con); ?>
    Il problema è che dal select multiplo il valore che mi salva è "array".
    come bisogna fare per impostare il salvataggio dei valori impostati, casomai separati da virgola ?
    grazie

  2. #2
    Utente di HTML.it L'avatar di neroux
    Registrato dal
    Aug 2009
    Messaggi
    1,973
    $nome dovrebbe essere vuota perché il select non ha l'attributo "name"

    Quindi lo dovresti aggiungere e anche due parentesi quadre per convertirlo in un array
    codice:
    <select multiple="multiple" id="nome" name="nome[]">
    Poi $_REQUEST['nome'] sarà un array che conterrà tutti i valori selezionati

    www.sitemeer.com » Quando un sito pare irraggiungibile

    Se ti piace ci puoi trovare anche su Facebook

  3. #3
    ciao, grazie per la risposta, ma aggiungendo l'attributo come mi hai consigliato mi compare sempre "array" come dato memorizzato nel db.
    dove sbaglio ?
    Grazie

  4. #4
    Utente di HTML.it L'avatar di neroux
    Registrato dal
    Aug 2009
    Messaggi
    1,973
    Come già scritto

    Originariamente inviato da neroux
    Poi $_REQUEST['nome'] sarà un array che conterrà tutti i valori selezionati
    ma tu la tratti come stringa

    www.sitemeer.com » Quando un sito pare irraggiungibile

    Se ti piace ci puoi trovare anche su Facebook

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.