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 :

ID de checkbox irrecupérable [PHP 5.3]


Sujet :

Langage PHP

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2013
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2013
    Messages : 11
    Points : 9
    Points
    9
    Par défaut ID de checkbox irrecupérable
    Bonjour! je m'en remets aux pros qui parcours ce forum pour essayer de comprendre mon problème.

    Le voici, j'ai donc un script java qui me permet d'afficher des checkbox différentes suivant le bouton radio coché, le soucis c'est que je n'arrive pas à récupérer l'id de la valeur qui se trouve dans chaque checkbox, le but étant à terme de supprimer les données correspondantes aux checkbox séléctionnées, voici mon code !

    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
    //balise html blabla
    <style type="text/css">#D1, #D2, #D3, #D4, #D5, #D6 {display: none;}</style>
            <script type="text/javascript">
    function showRadio() {
        var n = document.form.btnr.length;
        for(i=1;i<=n;i++) {
            if(document.getElementById('choix'+i).checked == true) {
                document.getElementById('D'+i).style.display = "block";
            } else {
                document.getElementById('D'+i).style.display = "none";
            }
        }
    }
    function changeImage(a) {
    	document.getElementById("img").src=a;
    }
            </script>	
    <body>
    <h2>Supprimer des photos</h2>
    <form name="form" action="Gestion/includes/maj.inc.php" method="post">
            <label for="choix1">Sites web </label><input type="radio" id="choix1" name="btnr" value="pro" onclick="showRadio()" /> </br>
            <label for="choix2">Applications </label><input type="radio" id="choix2" name="btnr" value="ama" onclick="showRadio()" /><br />
            <label for="choix3">Projets </label><input type="radio" id="choix3" name="btnr" value="ani" onclick="showRadio()"  /> <br />
            <label for="choix4">Paysages </label><input type="radio" id="choix4" name="btnr" value="asso" onclick="showRadio()" /><br />
            <label for="choix5">Divertissements </label><input type="radio" id="choix5" name="btnr" value="div"onclick="showRadio()" /><br />
            </p>
            <div id="D1">
                <h2>Miniatures :</h2>
                <div style="width:450px; height:100px; overflow-y:scroll">
    <?php 
    $sqlSelectImg="SELECT * FROM majrealisation WHERE categorie='sites web'";
    $reqSelectImg=mysql_query($sqlSelectImg);
    while($resSelectImg=mysql_fetch_array($reqSelectImg))
    {
    	$aSelectImg=$resSelectImg[1];
    	$aidImg=$resSelectImg[0];
    ?>
                    <label><?php echo $aSelectImg; ?><input type="checkbox" name="<?php echo $aidImg;?>" onclick='changeImage("images/realisations/<?php echo $aSelectImg; ?>");'>
                    </label>
    <?php }?>
    	</div>
            <h2>Photos:</h2> 
            <div style="width:450px; height:100px; overflow-y:scroll">
    <?php 
    $sqlSelectImgG="SELECT * FROM majrealisation WHERE categorie='sites web'";
    $reqSelectImgG=mysql_query($sqlSelectImgG);
    while($resSelectImgG=mysql_fetch_array($reqSelectImgG))
    {
    	$aSelectImgG=$resSelectImgG[2];
    	$aidImg=$resSelectImg[0];
    ?>
                <label><?php echo  $aidImg,$aSelectImgG;?> <input type="checkbox"  name="<?php echo $aidImg;?>" " value="<?php echo $aidImg;?>" " >
                </label></br>
    <?php }?>
    </p>
    </div>
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    //le script pour delete
    if (isset($_POST['supprImg']))
    {
    	$sqlSuppr="DELETE FROM majpresentation WHERE idimage='".aidImg."'";
    	mysql_querry($sqlSuppr);
    }
    }
    quand j'affiche ma requête sqlsupp la variable $aidImg de mon WHERE est vide ...

    et je n'arrive pas à la récupérer

    PS: le onClick sert à avoir un aperçu de l'image sélectionnée.

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    le soucis c'est que je n'arrive pas à récupérer l'id de la valeur
    l'id de la checkbox ou la valeur ?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    name="<?php echo $aidImg;?>" "
    La à la fin tu as un guillemet qui se ballade

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    if (isset($_POST['supprImg']))
    "supprImg" n'apparait pas dans ton code.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    $sqlSuppr="DELETE FROM majpresentation WHERE idimage='".aidImg."'";
    Il manque le $ de $aidImg ; et ou est défini $aidImg ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2013
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2013
    Messages : 11
    Points : 9
    Points
    9
    Par défaut
    Merci pour votre réponse !

    Alors en ce qui concerne les fautes de syntaxe, je n'en ai pas (qui sont problématique ) dans le code de ma page, celui ci est un peu modifié pour le rendre plus "présentable".

    En fait, je cherche à récupéré l'id de la photo sélectionnée pour ensuite pouvoir, en cliquant sur "supprimer l'image", la supprimer tout simplement
    il me faut l'ID car à chaque id correspond une image miniature, et le zoom de celle ci. Le fait de récupéré l'id me permet de supprimer la ligne entière en base

    je pense que pour résumé de manière simple (j'ai du mal ahah) l'id de la/les checkbox sélectionnée(s) n'arrive pas jusqu'à la requête de Delete...
    Voici le code originale:

    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
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    	<h2>Supprimer des photos</h2>
     
                                                    <form name="form" action="Gestion/includes/maj.inc.php" method="post">
                                                        <p><div class="wrapper pad_bot3">
                                                            <label for="choix1">Sites web </label><input type="radio" id="choix1" name="btnr" value="pro" onclick="showRadio()" /> </br>
                                                            <label for="choix2">Applications </label><input type="radio" id="choix2" name="btnr" value="ama" onclick="showRadio()" /><br />
                                                            <label for="choix3">Projets </label><input type="radio" id="choix3" name="btnr" value="ani" onclick="showRadio()"  /> <br />
                                                            <label for="choix4">Paysages </label><input type="radio" id="choix4" name="btnr" value="asso" onclick="showRadio()" /><br />
                                                   			<label for="choix5">Divertissements </label><input type="radio" id="choix5" name="btnr" value="div" onclick="showRadio()" /><br />
                                                        </p>
                                                 <div id="D1">
                                                         <h2>Miniatures :</h2>
                                                            <div style="width:450px; height:100px; overflow-y:scroll">
     
    													  <?php 
    														$sqlSelectImg="SELECT * FROM majrealisation WHERE categorie='sites web'";
    														$reqSelectImg=mysql_query($sqlSelectImg);
    														while($resSelectImg=mysql_fetch_array($reqSelectImg))
    															{
    																$aSelectImg=$resSelectImg[1];
    																$aidImg=$resSelectImg[0];
    															?>
     
                                                             <label>
    														 <?php echo $aSelectImg; ?>
                                                             <input type="checkbox" id="<?php echo $aidImg;?>" onclick='changeImage("images/realisations/<?php echo $aSelectImg; ?>");'>
                                                                 </label>
     
                                                                <?php }?>
     
                                                              </div>
                                                              <h2>Photos:</h2> 
     
                                                             <div style="width:450px; height:100px; overflow-y:scroll">
                                                            <?php 
    														$sqlSelectImgG="SELECT * FROM majrealisation WHERE categorie='sites web'";
    														$reqSelectImgG=mysql_query($sqlSelectImgG);
    														while($resSelectImgG=mysql_fetch_array($reqSelectImgG))
    															{
    																$aSelectImgG=$resSelectImgG[2];
    																$aidImg=$resSelectImg[0];
    															?>
                                                                <label>
    															<?php echo  $aidImg,$aSelectImgG;?> 
                                                                <input type="checkbox"  name="<?php echo $reqLoadImg['idimage'];?>" value="<?php echo "bool".$reqLoadImg['idimage'];?>" >
                                                                </label></br>
                                                                <?php }?>
    														</p>
     
                                                          </div>     
                                                        </div>
                                                  <div id="D2">
    														 <h2>Miniatures :</h2>
                                                            <div style="width:450px; height:100px; overflow-y:scroll">
     
                                                            <?php 
    														$sqlSelectImg="SELECT * FROM majrealisation WHERE categorie='applications'";
    														$reqSelectImg=mysql_query($sqlSelectImg);
    														while($resSelectImg=mysql_fetch_array($reqSelectImg))
    															{
    																$aSelectImg=$resSelectImg[1];
    																$aidImg=$resSelectImg[0];
    															?>
     
                                                                 <label>
    															 <?php echo $aSelectImg; ?> 
                                                                 <input type="checkbox" id="<?php echo $aidImg;?>" onclick='changeImage("images/realisations/<?php echo $aSelectImg; ?>");'>
                                                                 </label></br>
     
                                                                <?php }?>
     
                                                              </div>
                                                              <h2>Photos:</h2> 
     
                                                             <div style="width:450px; height:100px; overflow-y:scroll">
                                                            <?php 
    														$sqlSelectImgG="SELECT * FROM majrealisation WHERE categorie='applications'";
    														$reqSelectImgG=mysql_query($sqlSelectImgG);
    														while($resSelectImgG=mysql_fetch_array($reqSelectImgG))
    															{
    																$aSelectImgG=$resSelectImgG[2];
    																$aidImg=$resSelectImg[0];
    															?>
                                                                <label><?php echo  $aSelectImgG;?> <input type="checkbox"   id="<?php echo $aidImg;?>" ></label></br>
                                                                <?php }?>
    														</p>
     
                                                          </div>                                                     </div>
                                                 <div id="D3">
     
    														<h2>Miniatures :</h2>
                                                            <div style="width:450px; height:100px; overflow-y:scroll">
     
                                                            <?php 	$sqlSelectImg="SELECT * FROM majrealisation WHERE categorie='projets'";
     
    														$reqSelectImg=mysql_query($sqlSelectImg);
    														while($resSelectImg=mysql_fetch_array($reqSelectImg))
    															{
    																$aSelectImg=$resSelectImg[1];
    																$aidImg=$resSelectImg[0];
    															?>
     
                                                        <label>
    												    <?php echo $aSelectImg; ?> 
                                                        <input type="checkbox" name="<?php echo $reqLoadImg['id_image'];?>" value="<?php echo $reqLoadImg['id_image'];?>"  onclick='changeImage("images/realisations/<?php echo $aSelectImg; ?>");'>
                                                        </label>
     
     
                                                                <?php }?>
     
                                                              </div>
                                                              <h2>Photos:</h2> 
                                                            <?php echo $aidImg;?>
                                                             <div style="width:450px; height:100px; overflow-y:scroll">
                                                            <?php 
    														$sqlSelectImgG="SELECT * FROM majrealisation WHERE categorie='projets'";
    														$reqSelectImgG=mysql_query($sqlSelectImgG);
    														while($resSelectImgG=mysql_fetch_array($reqSelectImgG))
    															{
    																$aSelectImgG=$resSelectImgG[2];
    																$aidImg=$resSelectImg[0];
    															?>
                                                                <label>
    															<?php echo  $aSelectImgG;?> 
                                                                <input type="checkbox" name="projets" value="<?php echo $aidImg;?>" >
                                                                </label>
                                                                </br>
                                                                <?php }?>
    														</p>
     
                                                          </div></div>
                                                   <div id="D4">
     
    															<h2>Miniatures :</h2>
                                                            <div style="width:450px; height:100px; overflow-y:scroll">
     
                                                            <?php 
    														$sqlSelectImg="SELECT * FROM majrealisation WHERE categorie='paysages'";
    														$reqSelectImg=mysql_query($sqlSelectImg);
    														while($resSelectImg=mysql_fetch_array($reqSelectImg))
    															{
    																$aSelectImg=$resSelectImg[1];
    																$aidImg=$resSelectImg[0];
    															?>
     
                                                                 <label>
    															 	<?php echo $aSelectImg; ?>
                                                                    <input type="checkbox" id="<?php echo $aidImg;?>" onclick='changeImage("images/realisations/<?php echo $aSelectImg; ?>");'>
                                                                 </label></br>
     
                                                                <?php }?>
     
                                                              </div>
                                                              <h2>Photos:</h2> 
     
                                                             <div style="width:450px; height:100px; overflow-y:scroll">
                                                            <?php 
    														$sqlSelectImgG="SELECT * FROM majrealisation WHERE categorie='paysages'";
    														$reqSelectImgG=mysql_query($sqlSelectImgG);
    														while($resSelectImgG=mysql_fetch_array($reqSelectImgG))
    															{
    																$aSelectImgG=$resSelectImgG[2];
    																$aidImg=$resSelectImg[0];
    															 ?>
                                                                <label><?php echo  $aSelectImgG;?> <input type="checkbox" id="<?php echo $aidImg;?>" ></label></br>
                                                                <?php }?>
    														</p>
     
                                                          </div></div>  
                                                        <div id="D5">
    														<h2>Miniatures :</h2>
                                                            <div style="width:450px; height:100px; overflow-y:scroll">
     
                                                            <?php 
    														$sqlSelectImg="SELECT * FROM majrealisation WHERE categorie='divertissements'";
    														$reqSelectImg=mysql_query($sqlSelectImg);
    														while($resSelectImg=mysql_fetch_array($reqSelectImg))
    															{
    																$aSelectImg=$resSelectImg[1];
    																$aidImg=$resSelectImg[0];
    															?>
     
                                                                 <label><?php echo $aSelectImg; ?> <input type="checkbox"  id="<?php echo $aidImg;?>" onclick='changeImage("images/realisations/<?php echo $aSelectImg; ?>");'></label></br>
     
                                                                <?php }?>
     
                                                              </div>
                                                             <h2>Photos:</h2> 
     
                                                             <div style="width:450px; height:100px; overflow-y:scroll">
                                                            <?php 
    														$sqlSelectImgG="SELECT * FROM majrealisation WHERE categorie='divertissements'";
    														$reqSelectImgG=mysql_query($sqlSelectImgG);
    														while($resSelectImgG=mysql_fetch_array($reqSelectImgG))
    															{
    																$aSelectImgG=$resSelectImgG[2];
    																$aidImg=$resSelectImg[0];
    															?>
                                                                <label><?php echo  $aSelectImgG;?> <input type="checkbox" id="<?php echo $aidImg;?>" ></label></br>
                                                                <?php }?>
    														</p>
     
                                                          </div>                                                     </div>
    													</div> 
                                                        <div class="col1 ">
                                                        <h2>Aperçu:</h2></br><div id="main_img"><img id="img" src="images/realisations/<?php echo $aSelectImg; ?>"></div>
     
                                                        </br>
        												<center>
                                                        <input type='submit' class="button1"name='supprImg' value="Supprimer l'image"/>
                                                        </center>
                                                    </form>
    le supprImg est donc ici.

  4. #4
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Points : 44 155
    Points
    44 155
    Par défaut
    Je ne comprends pas bien ce que tu fais.
    Si tu veux faire intéragir Javascript (evenement onclick) avec une requête par PHP, il faudra passer par Ajax.
    Si tu veux ne veut pas d'interaction alors tu n'as pas besoin d'Ajax et tes checkbox seront recupérées simplement dans $_POST.
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Mai 2013
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Corrèze (Limousin)

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Mai 2013
    Messages : 11
    Points : 9
    Points
    9
    Par défaut
    D'accord merci bien ! je vais chercher dans cette direction alors!

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [JSP]checkbox
    Par orisis dans le forum Servlets/JSP
    Réponses: 6
    Dernier message: 16/04/2013, 13h53
  2. [VB.NET] Insérer une colonne de CheckBox dans un DataGrid
    Par Manue.35 dans le forum Windows Forms
    Réponses: 2
    Dernier message: 22/05/2003, 11h44
  3. Checkbox
    Par rgarnier dans le forum XMLRAD
    Réponses: 11
    Dernier message: 06/03/2003, 10h48
  4. Couleur d'un CheckBox
    Par benj63 dans le forum C++Builder
    Réponses: 4
    Dernier message: 15/07/2002, 14h48
  5. CheckBox en Read Only
    Par MrJéjé dans le forum C++Builder
    Réponses: 7
    Dernier message: 23/06/2002, 15h00

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