IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Probleme textarea dans formulaire php/mysql


Sujet :

Langage PHP

  1. #1
    Nouveau Candidat au Club
    Inscrit en
    Août 2010
    Messages
    1
    Détails du profil
    Informations forums :
    Inscription : Août 2010
    Messages : 1
    Points : 1
    Points
    1
    Par défaut Probleme textarea dans formulaire php/mysql
    Bonjour, je suis entrain de realiser un questionnaire dynamique en php/mysql

    dans l'interface d'ajout j'ai un probleme , je veut recuperer les possibilités de reponse dans un champs textarea chaque ligne contient une possibilté et après je veut que ses valeurs s'enregistre dans la table reponse chaqu'une dans un enregistrement mais j'ai pas trouvé la solution .

    c'est la pge de formulaire d'ajout:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><head>
    <link type="text/css" rel="StyleSheet" href="admin/style.css">
     
    	<title>
    	Questionnaire E-Learning
    	</title>
    <script type="text/javascript">
    	function THEFUNCTION(i) {
    		var choix1 = document.getElementById('choix1');
    		switch(i) {
    				case 0 : 	choix1.style.display = '';
    							choix2.style.display = 'none';
    				break;
    				case 1 :	choix2.style.display = '';
    							choix1.style.display = 'none';
    							break;
    				default: 	choix1.style.display = 'none'; 
    							choix2.style.display = 'none';
    							break;
     
    	}
    	}
    </script>
     
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    </head>
    <body bgcolor='#0099CC' link='#000080' vlink='#000080' alink='#FFFF00'><font face='verdana' size='2'>
    <table width='95%' align='center' style='border-collapse: collapse' bordercolor='#0A47FF' bgcolor='#E5F9FF' border='1' cellspacing='0'>
    	<tr>
    		<td>
    <form action="traitementadd.php" name="form_add" method="post" class="formulaire"><!-- START THE SURVEY -->
    	<table width='100%' align='center' cellspacing='0' cellpadding='2'>
     
    		<tr>
    			<td align='center' bgcolor='#E5F9FF'><font size='5' color='#0A47FF'><b>Questionnaire Evaluation de la Qualité du Processus d’Apprentissage d’un cours en ligne</b></font><br />
    				<font size='2' color='#111111'>Software Engineering Group<br>Departement informatique<br> Institut Superieur de gestion 
    			</td>
     
    		</tr>
    		<tr>
    			<td align='center' bgcolor='#0099CC' valign='middle'>
     
    			</td>
    		</tr>
    	</table>
    <!-- START THE GROUP -->
    	<table width='99%' align='center' border='0' bgcolor='#FFFFFF'>
    		<tr>
    			<td align='center'>
    				<font face='verdana' size='3' color='#0A47FF'><b><br />La satisfaction de l’apprenant </b></font>
     
     
     
    <!-- PRESENT THE QUESTIONS -->
    	<!-- NEW QUESTION -->
    				<div id='question123'>
    			  <table width='75%' align='center' border='1' style='border-collapse: collapse' bordercolor='#0099CC' bgcolor='white'>
     
    						<tr>
     
    							<td align='center'>
     
    								<table width='100%' cellspacing='0'>
     
    									<tr>
     
    										<td align='center' bgcolor='#E5F9FF'>
     
    											<font size='2' color='#0033CC'><b><label for='5X21X123'>Ajouter une question<b></label></b></td>
     
    									</tr>
     
     
    									<tr>
     
    									  <td align='center'>
     
    										<table class='question'>
     
          <td align="center" class="answertext">Categorie :</td>
          <td>
           <select name="categories" id="categories" size="1">
                      <option name="" value="0"></option>
    <?php
    include("connect.php");
    								mysql_query("SET NAMES UTF8"); 
    $sql="SELECT *
    FROM categorie";
    $req=mysql_query($sql)
    or die('Erreur SQL !
    '.$sql.'
    '.mysql_error()); 
    while($resultat=mysql_fetch_assoc($req))
    {
    	$id_categorie=$resultat['id_categorie'];
    	$libelle_cat=$resultat['libelle_cat'];
    echo '<option value="'.$id_categorie.'">'.$libelle_cat; }
    ?>
    </option>
    </select>    <br />    </td>
        </tr>
        <tr>
          <td align="center" class="answertext">Libellé question :</td>
          <td><input type="text" id="libelle_quest" name="libelle_quest"/>
        <br />
        </td>
        </tr>
         <tr>
          <td align="center" class="answertext">Name:</td>
          <td><input type="text" id="Name" name="Name"/>
        <br />
        </td>
        </tr>
          <tr>
          <td align="center" class="answertext">Réponse :</td>
          <td><select name="type" id="type" onChange="THEFUNCTION(this.selectedIndex);">
    <option value="Multichoix">Multichoix</option>
    <option value="choix unique">Choix unique</option>
    <option value="champs texte">Champs texte</option>
    </select>    <br />
     
        </td>
        </tr>
        <tr>
          <td align="center" class="answertext">Réponse :</td>
          <td><div style="display:none;" id="choix1">
    	<label for="Multichoix">Multichoix: </label>
    	<textarea name="Multichoix" id="Multichoix" ></textarea>
    </div>
    <div style="display:none;" id="choix2">
    	<label for="choix_unique">choix unique:</label>
    	<textarea name="choix_unique" id="choix_unique"></textarea>
    </div>
     
        </td>
        </tr>
    					<td>&nbsp;</td>
    				</tr>
    			</table></td>
     
    									</tr>
     
    									<tr>
     
    										<td align='center' bgcolor='#E5F9FF'>
     
    											<font size='1'></font>
     
    										</td>
     
    									</tr>
     
    								</table>
     
    							</td>
     
    						</tr>
     
    					</table>
     
    					<table>
     
    						<tr>
     
    							<td height='1'></td>
     
    						</tr>
     
    					</table>
    				</div>
     
    <!-- END THE GROUP -->
    			</td>
    		  </tr>
    		</table>
     
    		<table><tr><td height='2'></td></tr></table>
     
     
    <!-- PRESENT THE NAVIGATOR -->
    		<table width='100%' align='center' bgcolor='#E5F9FF'>
    		 <tr>
    		  <td width="50%" height="40" align='center' valign='middle'><input class='submit' type='submit' value=' Ajouter' name='move2' accesskey="s"/></td>
    		 </tr>
    		</table>
    <!-- group2.php -->
     
    </form>
    		</td>
    	</tr>
    </table>
    <table width='95%' align='center' style='border-collapse: collapse' bordercolor='#333333' bgcolor='#0099CC' border='0' cellspacing='0'>
     <tr>
    <!--  <td align='right'><font size='2'>  -->
    <!--    Adopted from <a href='http://www.phpsurveyor.org/' target='_blank'>PHPSurveyor</a>  -->
    <!--  </td>   -->
     </tr>
    </table>
    </body>
     
    </html>
    Le code de traitement de formulaire

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Ajout d'une question</title>
    </head>
    <body>
    <?php
    include("connect.php");
    								mysql_query("SET NAMES UTF8"); 
    $id_categorie=$_POST["categories"];
    $libelle_quest=$_POST["libelle_quest"];
    $type=$_POST["type"];
    $sql1 = "INSERT INTO question 
       (id_categorie,libelle_quest,type)
    VALUES 
       ('$id_categorie','$libelle_quest','$type') ;";
       mysql_query($sql1) or die('Erreur SQL !
    '.$sql1.'
    '.mysql_error());
       if(mysql_query($sql1) )
    $id_question = mysql_insert_id(); 
       if($type=="Multichoix")
    {
    	$reponse=$_POST["Multichoix"];
    	explode("/n",$reponse);
    }
    if($type=="choix unique"){
    	$reponse=$_POST["choix_unique"];
    		explode("/n",$reponse);
    }
    echo $reponse;
     
     
    $sql2 = "INSERT INTO reponse 
       (libelle_rep,id_question)
    VALUES 
       ('$reponse','$id_question') ;";
       mysql_query($sql2) or die('Erreur SQL !
    '.$sql2.'
    '.mysql_error());
     
    header('location:questions.php');
     
    ?>
    </body>
    </html>
    SVP ,pouvez vous m'aidez

  2. #2
    Expert éminent
    Avatar de Benjamin Delespierre
    Profil pro
    Développeur Web
    Inscrit en
    Février 2010
    Messages
    3 929
    Détails du profil
    Informations personnelles :
    Âge : 36
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Opérateur de télécommunications

    Informations forums :
    Inscription : Février 2010
    Messages : 3 929
    Points : 7 762
    Points
    7 762
    Par défaut
    textarea chaque ligne contient une possibilté
    ça ressemble à un select multiple non ? Pourquoi ne pas avoir fait tout bêtement

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    <select multiple="multiple" name="un_nom[]">
      <option value="1">A</option>
      <option value="2">B</option>
      <option value="3">C</option>
    </select>
    Coté PHP tu réccupères directement un tableau.

  3. #3
    Membre régulier Avatar de Pierrot2Mars
    Homme Profil pro
    Développeur Web
    Inscrit en
    Novembre 2010
    Messages
    79
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Novembre 2010
    Messages : 79
    Points : 108
    Points
    108
    Par défaut
    Salut,
    Ton explode n'a pas de cible.
    Remplace ces lignes :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    explode("/n",$reponse);
    Par :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $reponse = explode("/n",$reponse);

Discussions similaires

  1. Saisie automatique dans un formulaire PHP/MySQL
    Par marina_db dans le forum Langage
    Réponses: 6
    Dernier message: 01/07/2014, 12h04
  2. Problème de syntaxe dans un formulaire php-mysql
    Par alex45500 dans le forum Langage
    Réponses: 3
    Dernier message: 05/11/2012, 15h56
  3. [MySQL] Formulaire PHP ->MySQL
    Par shub dans le forum PHP & Base de données
    Réponses: 14
    Dernier message: 09/02/2010, 22h42
  4. [MySQL] Champs à nul dans formulaire PHP, Mysql refuse l'enregistrement
    Par arnaudperfect dans le forum PHP & Base de données
    Réponses: 7
    Dernier message: 18/02/2009, 22h10
  5. [MySQL] Bug Formulaire PHP-MySQL
    Par Davboc dans le forum PHP & Base de données
    Réponses: 17
    Dernier message: 01/03/2006, 15h15

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo