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

PHP & Base de données Discussion :

Affichage et mise a jour de données via un lien


Sujet :

PHP & Base de données

  1. #1
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 124
    Points : 193
    Points
    193
    Par défaut Affichage et mise a jour de données via un lien
    Bonjour tout le monde


    Voici les erreurs:

    Notice: Undefined variable: action in C:\Program Files\EasyPHP 2.0b1\www\Misajliste.php on line 12

    Notice: Undefined variable: action in C:\Program Files\EasyPHP 2.0b1\www\Misajliste.php on line 35

    Notice: Undefined variable: id in C:\Program Files\EasyPHP 2.0b1\www\Misajliste.php on line 47


    Voici les codes:

    ligne 12:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    if($action == "maj")
     
    {
     
    	if(empty($id)||empty($desig)||empty($vl)||empty($px)||empty($dpt)||empty($vil)||empty($im)||empty($texte)||empty($type)||empty($genretype)||empty($date))
     
     
    }


    ligne 35:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    elseif($action == "suppr")
    {
     
    }


    Ligne 47:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
     
    sql = "DELETE FROM $tblog WHERE ref_loge = '$id'";
     
    mysql_query($sql);
     
    mysql_close($lien);

    Formulaire où doivent venir les données par un lien.

    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
     
     
    <form action="Misajliste.php" method="post" enctype = "multipart/form_data">
    <input type="hiden" name="enregistre" value="oui">
    <input type="hiden" name="id" value="<?php echo $id;?>">
     
     
    <TABLE  BORDER="1" style="BORDER-COLOR:#FF0033">
     
    <tr><td colspan = "2">
     
     
    </td></tr>
     
    <tr><td><input type="text" name="desig" value="<?php echo $habitat['titre'];?>"></td><td><input type="text" name="date" value="<?php echo $habitat['date'];?>"></td></tr>
    <tr><td><textarea name="texte" rows="12" cols="50"><?php echo $habitat['information'];?></textarea></td><td>
     
     
     
    <p><SELECT name="locachat">
     
     
     
    		<option style="background-color:yellow" value="Location" <?php if ($habitat['locachat'] == "Location") echo "SELECTED"; ?>>Location</option>
     
    		<option style="background-color:yellow" value="vente" <?php if ($habitat['locachat'] == "vente") echo "SELECTED"; ?>>vente</option>
    		</SELECT></p>
     
     
     
    <p><SELECT name="logement">
     
     
    		<option style="background-color:yellow" value="Maison" <?php if ($habitat['logement'] == "Maison") echo "SELECTED"; ?>>Maison</option>
     
    		<option style="background-color:yellow"value="Appartement" <?php if ($habitat['logement'] == "Appartement") echo "SELECTED"; ?>>Appartement</option>
    		</SELECT></p>
     
     
     
     
     
     
     
    <p><SELECT name="type">
     
     
    		<option style="background-color:yellow" value="Studio" <?php if ($habitat['type'] == "Studio") echo "SELECTED"; ?>>Studio</option>
     
    		<option style="background-color:yellow" value="T1" <?php if ($habitat['type'] == "T1") echo "SELECTED"; ?>>-T1-</option>
     
     
    		<option style="background-color:yellow" value="T2" <?php if ($habitat['type'] == "T2") echo "SELECTED"; ?>>-T2-</option>
     
     
    		</SELECT></p>
     
     
    <p><input type="text" name="px" value="<?php echo $habitat['prix']; ?>"></p>
     
     
    <p><SELECT name="departement">
     
    				<option style="background-color:yellow" value="80-somme" <?php if ($habitat['departement'] == "80-somme") echo "SELECTED"; ?>>80-somme</option>
    				<option style="background-color:yellow" value="02-aisne" <?php if ($habitat['departement'] == "02-aisne") echo "SELECTED"; ?>>02-aisne</option>
    				<option style="background-color:yellow" value="60-oise" <?php if ($habitat['departement'] == "60-oise") echo "SELECTED"; ?>>60-oise</option>
    				</SELECT></p>
     
    <p><SELECT name="ville">
     
    			<option style="background-color:yellow" value="Amiens" <?php if ($habitat['ville'] == "Amiens") echo "SELECTED"; ?>>Amiens</option>
     
    			<option style="background-color:yellow" value="St-Quentin"<?php if ($habitat['ville'] == "St-Quentin") echo "SELECTED"; ?>>St-Quentin</option>
     
    			<option style="background-color:yellow" value="Creil" <?php if ($habitat['ville'] == "Creil") echo "SELECTED"; ?>>Creil</option>
    			</SELECT></p>
     
     
     
     
    </td></tr>
     
     
    </TABLE>
     
    <br>
     
    <select name="action">
    <option value="maj">Enregistrer la mise à jour</option>
     
    <option value="suppr">supprimer</option>
    </select>
    <br>
    <input type="submit" name="valide" value="Effectuer">
     
     
     
     
     
    Fichier le lien:
     
     
    <?php
     
    include("Haut.inc.php");
    include("id.inc.php");
     
     
     
     
    $lien = mysql_connect($bdserver, $bdlogin, "");
     
    mysql_select_db($bdd);
     
    $sql = "SELECT * FROM $tblog";
     
    $result = mysql_query($sql);
     
     
    echo "<TABLE  BORDER=1 style=BORDER-COLOR:#FF0033>";
    echo "<tr><th>Ref</th><th>Désigantion</th><th>Vente ou location</th><th>Prix</th><th>Departement</th><th>Ville</th><tr>";
     
     
    while ($habitat = mysql_fetch_array($result)){
     
     
    $id = $habitat['ref_loge'];
    $desig = $habitat['titre'];
    $vl = $habitat['locvente'];
    $px = $habitat['prix'];
    $dpt = $habitat['departement'];
    $vil = $habitat['ville'];
    $texte =$habitat['information'];
    $im = $habitat['image'];
    $type = $habitat['genre'];
    $genretype = $habitat['type'];
    $date = $habitat['date'];
     
     
     
     
    echo "<tr>";
     
    echo "<td>$id</td>";
     
    echo "<td><a href=Misajliste.php?id=$id>$desig</a></td>";
     
    echo "<td>$vl</td>";
     
    echo "<td>$px</td>";
     
    echo "<td>$dpt</td>";
     
    echo "<td>$vil</td>";
     
    }
     
    echo "</TABLE>";
    mysql_close($lien);
     
    include("Bas.inc.php");
    ?>

    Mon problème est que je n'arrive pas à transmettre la clé primaire de la liste au Misajliste.php.

    Comment puis je résoudre ce problème?

    Merci.

    A +

  2. #2
    Membre averti Avatar de sacricri
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    324
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 324
    Points : 384
    Points
    384
    Par défaut
    En gros, ca te dit que les variables $action et $id ne sont pas définies plus haut, elles n'existent pas pour lui

    Qui plus est, tes if ne contiennent aucune instructions. Dans ton premier if, tu fais un autre if mais sans rien après.
    Dans le deuxième (le elseif), c'est vide.

  3. #3
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 124
    Points : 193
    Points
    193
    Par défaut
    Rebonjour

    Donc, je dois les déclarer?

    Pourtant il sont déclarer.



    Qui plus est, tes if ne contiennent aucune instructions. Dans ton premier if, tu fais un autre if mais sans rien après.
    Dans le deuxième (le elseif), c'est vide.
    Je limité le code car, il y a plus de 200 lignes

    A +

  4. #4
    Membre averti Avatar de sacricri
    Profil pro
    Inscrit en
    Juin 2008
    Messages
    324
    Détails du profil
    Informations personnelles :
    Âge : 40
    Localisation : France

    Informations forums :
    Inscription : Juin 2008
    Messages : 324
    Points : 384
    Points
    384
    Par défaut
    met en fichier joint ta page Misajliste.php stp, je vais regarder

  5. #5
    Membre averti
    Homme Profil pro
    Consultant ERP
    Inscrit en
    Mai 2006
    Messages
    257
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Oise (Picardie)

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

    Informations forums :
    Inscription : Mai 2006
    Messages : 257
    Points : 318
    Points
    318
    Par défaut
    Pour les
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    if($action == "maj")
     
    {
     
    	if(empty($id)||empty($desig)||empty($vl)||empty($px)||empty($dpt)||empty($vil)||empty($im)||empty($texte)||empty($type)||empty($genretype)||empty($date))
     
     
    }
    peu être que tu fais le test sur les variables avant qu'elles ne soient envoyés
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    if(isset($_GET['id']))
    	{
    	.....
    	}
    Et je ne te vois les récupérer nulle part tu test directement
    Je crois aussi que tu as inverser le code, tu affiche et tu test sur des variables qui n'existent pas encore $habitat

  6. #6
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 124
    Points : 193
    Points
    193
    Par défaut
    Bonsoir tout le monde

    Voici les fichiers.

    Je ne comprend pas pourquoi ca ne fonctionne pas.

    Ce code vient d'un livre pour php 4 et j'utilise php 5.

    Merci.

    A +
    Fichiers attachés Fichiers attachés

  7. #7
    Membre averti
    Homme Profil pro
    Consultant ERP
    Inscrit en
    Mai 2006
    Messages
    257
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Oise (Picardie)

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

    Informations forums :
    Inscription : Mai 2006
    Messages : 257
    Points : 318
    Points
    318
    Par défaut
    Bonsoir,
    Notice: Undefined variable: action in C:\Program Files\EasyPHP 2.0b1\www\Misajliste.php on line 12

    Notice: Undefined variable: action in C:\Program Files\EasyPHP 2.0b1\www\Misajliste.php on line 35

    Notice: Undefined variable: id in C:\Program Files\EasyPHP 2.0b1\www\Misajliste.php on line 47
    Ces erreurs apparaissent par ce que tu test sur des variables qui n'existent pas encore, par ce qu'il n'existeront que lorsque ton formulaire sera envoyé alors que dans le premier affichaged de la page ton formulaire n'est pas encore envoyé et donc les variables, $action, $id n'existent pas encore. Tu dois faire un test comme ça
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
     
    if(isset($_POST['action']) && $_POST['action'] == "maj")
           {
              .......
            }
    else if (isset($_POST['action']) && $_POST['action'] == "suppr")
            {
     
            }
    La même chose pour $habitat
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    <?php if (isse($_POST['habitat']) && ($habitat['locachat'] == "Location")) echo "SELECTED"; ?>
    Et il vaut mieux que tu met register_globals à off dans ton fichier php.ini et qu e tu accède à tes variables envoyé par les formulaires par le biais des tableaux super globaux, $_POST et $_GET ou $_REQUEST.
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    	if(empty($_POST['id'])||empty($_POST['desig'])....

  8. #8
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 124
    Points : 193
    Points
    193
    Par défaut
    Bonjour tout le monde

    J'ai fais une erreur, c'est listlog que je voulais envoyer, au lieu de messagerie.

    listlog à un lien avec Misajliste.

    Donc, il faut que je déclare les variable.

    A+
    Fichiers attachés Fichiers attachés

  9. #9
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 124
    Points : 193
    Points
    193
    Par défaut
    Bonsoir tout le monde

    J'ai réglé mon problème en metant $ident = $_GET['id'];.

    Mais j'ai quand même cet erreur.

    Erreur:

    Notice: Undefined variable: action in C:\Program Files\EasyPHP 2.0b1\www\Misajliste.php on line 24

    Notice: Undefined variable: action in C:\Program Files\EasyPHP 2.0b1\www\Misajliste.php on line 41


    Pourtant action et déclaré dans le select.

    Dois je le déclarer?

    Merci

    A +
    Fichiers attachés Fichiers attachés

  10. #10
    Membre averti
    Homme Profil pro
    Consultant ERP
    Inscrit en
    Mai 2006
    Messages
    257
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Oise (Picardie)

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

    Informations forums :
    Inscription : Mai 2006
    Messages : 257
    Points : 318
    Points
    318
    Par défaut
    Bonjour, est ce que vous avez essayé la fonction que je vous ai proposé?!!
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
    if(isset($_POST['action']))
    {
              if($_POST['action']=='maj')
                   {
    }
    }

  11. #11
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 124
    Points : 193
    Points
    193
    Par défaut
    Bonsoir

    J'ai modifié le code en piece jointe.

    il ne lance pas d'erreur à l'ouverture de la page, mais à l'execution il ne reconait pas l'id.

    Pourtant ca devrait marcher.

    Merci

    A +
    Fichiers attachés Fichiers attachés

  12. #12
    Débutant  
    Profil pro
    Inscrit en
    Novembre 2003
    Messages
    1 124
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Novembre 2003
    Messages : 1 124
    Points : 193
    Points
    193
    Par défaut
    Bonjour tout le monde

    J'ai re modifié le fichier, mais élace ce ne fonctionne pas.

    Voici l'erreur:

    Notice: Undefined index: id in C:\Program Files\EasyPHP 2.0b1\www\Misajliste.php on line 98
    Je pense que mon problème est que je n'arrive pas à récupérer l'id.

    Comment puis je le récuprérer?

    Merci

    A +
    Fichiers attachés Fichiers attachés

  13. #13
    Membre averti
    Homme Profil pro
    Consultant ERP
    Inscrit en
    Mai 2006
    Messages
    257
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Oise (Picardie)

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

    Informations forums :
    Inscription : Mai 2006
    Messages : 257
    Points : 318
    Points
    318
    Par défaut
    Bonjour,
    C'est plutôt $_POST['id'] et non $_GET['id'], c'est pour cela que tu n'arrive pas à le récupérer.

Discussions similaires

  1. Réponses: 3
    Dernier message: 11/01/2013, 14h28
  2. Mise a jour de données via formulaire
    Par crashfire dans le forum Macros et VBA Excel
    Réponses: 24
    Dernier message: 25/01/2011, 06h10
  3. Réponses: 3
    Dernier message: 15/09/2008, 08h32
  4. mise à jour des données via GridView ?
    Par gregcat dans le forum ASP.NET
    Réponses: 1
    Dernier message: 02/10/2007, 13h18
  5. mise a jours des données sous access
    Par puyopuyo dans le forum ASP
    Réponses: 4
    Dernier message: 25/05/2004, 12h46

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