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 :

Formulaire d'insertion et upload


Sujet :

Langage PHP

  1. #1
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2007
    Messages
    610
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2007
    Messages : 610
    Points : 66
    Points
    66
    Par défaut Formulaire d'insertion et upload
    bonjour, j'ai crée une formulaire qui fais l'insertion des information dans la BD mais il y a un champs qui pas ajouter si un champ qui j'ai fait l'upload d'une photo le code de la formulaire est
    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
    <form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
              <table width="465" align="center">
                <tr valign="baseline">
                  <td width="136" height="34" align="right" nowrap="nowrap"><strong>Code enseignant:</strong></td>
                  <td width="317"><input type="text" name="code" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Code groupe<br /> 
                  de recherche:</strong></td>
                  <td><input type="text" name="code_gr" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Nom:</strong></td>
                  <td><input type="text" name="nom" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Prenom:</strong></td>
                  <td><input type="text" name="prenom" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Grade:</strong></td>
                  <td><input type="text" name="grade" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Tele:</strong></td>
                  <td><input type="text" name="tele" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Fax:</strong></td>
                  <td><input type="text" name="fax" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Adresse:</strong></td>
                  <td><input type="text" name="adresse" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Email:</strong></td>
                  <td><input type="text" name="email" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Photo:</strong></td>
                  <td><label>
                    <input type="file" name="photo" id="photo" />
                    <?
    // Taille max des fichiers (octets)
    $MFS=10000000024;
    // Répertoire de stockage
    $rep="upload/";
     
    if(isset($_FILES['userfile'])) {
    if($_FILES['userfile']['size']>0) {
       $savefile= $rep.$_FILES['userfile']['name'];
       $temp = $_FILES['userfile']['tmp_name'];
       if (move_uploaded_file($temp, $savefile)) { ?>
          <b>Votre fichier a bien été enregistré !</b>
    <BR>Nom : <?echo $_FILES['userfile']['name'];?>
    <BR>Taille : <?echo $_FILES['userfile']['size'];?> o
    <BR>Type : <?echo $_FILES['userfile']['type'];?>
    <?   } else { ?>
          <b>Erreur d'enregistrement !</b>
       <? }
     
    } else { ?>
       <b>Trop gros fichier !</b>
       <i>( <? echo $MFS;?> octets max.)</i>
    <? } 
    } ?>
                  </label></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Service/membre:</strong></td>
                  <td><input type="text" name="service_membre" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right" valign="top"><strong>Diplome:</strong></td>
                  <td><textarea name="diplome" cols="50" rows="5"></textarea>              </td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right" valign="top"><p><strong>Enseignament et</strong><strong><br />
                    cours récents:</strong></p>
                  </td>
                  <td><textarea name="Enseignament_cours" cols="50" rows="5"></textarea>              </td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">&nbsp;</td>
                  <td><input type="submit" value="Insérer" /></td>
                </tr>
              </table>
              <input type="hidden" name="MM_insert" value="form1" />
          </form>
    touts les champs insérer sauf le champ 'photo' , je sais qu'il y a une erreur dans la recupiration de chemin puisque le code de la recupiration est
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    GetSQLValueString($_POST['photo'], "text"),
    et la requete d'insertion
    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
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
      $insertSQL = sprintf("INSERT INTO enseignant (code, code_gr, nom, prenom, grade, tele, fax, adresse, email, photo, service_membre, diplome, Enseignament_cours) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                           GetSQLValueString($_POST['code'], "text"),
                           GetSQLValueString($_POST['code_gr'], "int"),
                           GetSQLValueString($_POST['nom'], "text"),
                           GetSQLValueString($_POST['prenom'], "text"),
                           GetSQLValueString($_POST['grade'], "text"),
                           GetSQLValueString($_POST['tele'], "int"),
                           GetSQLValueString($_POST['fax'], "int"),
                           GetSQLValueString($_POST['adresse'], "text"),
                           GetSQLValueString($_POST['email'], "text"),
                           GetSQLValueString($_POST['photo'], "text"),
                           GetSQLValueString($_POST['service_membre'], "text"),
                           GetSQLValueString($_POST['diplome'], "text"),
                           GetSQLValueString($_POST['Enseignament_cours'], "text"));
    comment pui-je recupirer le chemin de la photo

  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 chemin de la photo tu le connais déjà puisque c'est toi qui le defini :

    Je cite ton code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    $rep="upload/";
    $savefile= $rep.$_FILES['userfile']['name'];

  3. #3
    Membre actif Avatar de juliens9
    Profil pro
    Développeur Web
    Inscrit en
    Mars 2007
    Messages
    192
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mars 2007
    Messages : 192
    Points : 237
    Points
    237
    Par défaut
    Le chemin contient deux composantes :

    - le fichier "upload/blabla"
    - le fichier dans lequel se trouve ton script,

    Si ton script se trouve dans /home/web/

    ton fichier se trouvera alors dans /home/web/upload/monfichier

  4. #4
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2007
    Messages
    610
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2007
    Messages : 610
    Points : 66
    Points
    66
    Par défaut
    bonjour,
    je sais que les photo est dans le répertoire 'upload' mais comment je dis ça dans la requete 'insertinto' au même temps que l'upload

  5. #5
    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 t'ai repondu, dans ton champ photo tu fais inserer la valeur
    $_FILES['userfile']['name'];
    et pas $_POST['photo']

  6. #6
    Membre du Club
    Femme Profil pro
    Étudiant
    Inscrit en
    Septembre 2007
    Messages
    610
    Détails du profil
    Informations personnelles :
    Sexe : Femme
    Localisation : Algérie

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2007
    Messages : 610
    Points : 66
    Points
    66
    Par défaut
    j'ai essayé mais l'insersion ne faite pas meme la phto n'uploader pas a la repertoire avans elle fonctionne mais maintenant la formulaire ne marche pas partout
    le code de la formulaire est
    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
    <form action="<?php echo $editFormAction; ?>" method="post" enctype="multipart/form-data" name="form1" id="form1">
              <table width="465" align="center">
                <tr valign="baseline">
                  <td width="136" height="34" align="right" nowrap="nowrap"><strong>Code enseignant:</strong></td>
                  <td width="317"><input type="text" name="code" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Code groupe<br /> 
                  de recherche:</strong></td>
                  <td><input type="text" name="code_gr" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Nom:</strong></td>
                  <td><input type="text" name="nom" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Prenom:</strong></td>
                  <td><input type="text" name="prenom" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Grade:</strong></td>
                  <td><input type="text" name="grade" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Tele:</strong></td>
                  <td><input type="text" name="tele" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Fax:</strong></td>
                  <td><input type="text" name="fax" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Adresse:</strong></td>
                  <td><input type="text" name="adresse" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Email:</strong></td>
                  <td><input type="text" name="email" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Photo:</strong></td>
                  <td><label>
                    <input type="file" name="userfile" id="userfile" />
                    <?
    // Taille max des fichiers (octets)
    $MFS=10000000024;
    // Répertoire de stockage
    $rep="upload/";
     
    if(isset($_FILES['userfile'])) {
    if($_FILES['userfile']['size']>0) {
       $savefile= $rep.$_FILES['userfile']['name'];
       $temp = $_FILES['userfile']['tmp_name'];
       if (move_uploaded_file($temp, $savefile)) { ?>
          <b>Votre fichier a bien été enregistré !</b>
    <BR>Nom : <?echo $_FILES['userfile']['name'];?>
    <BR>Taille : <?echo $_FILES['userfile']['size'];?> o
    <BR>Type : <?echo $_FILES['userfile']['type'];?>
    <?   } else { ?>
          <b>Erreur d'enregistrement !</b>
       <? }
     
    } else { ?>
       <b>Trop gros fichier !</b>
       <i>( <? echo $MFS;?> octets max.)</i>
    <? } 
    } ?>
                  </label></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right"><strong>Service/membre:</strong></td>
                  <td><input type="text" name="service_membre" value="" size="32" /></td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right" valign="top"><strong>Diplome:</strong></td>
                  <td><textarea name="diplome" cols="50" rows="5"></textarea>              </td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right" valign="top"><p><strong>Enseignament et</strong><strong><br />
                    cours récents:</strong></p>
                  </td>
                  <td><textarea name="Enseignament_cours" cols="50" rows="5"></textarea>              </td>
                </tr>
                <tr valign="baseline">
                  <td nowrap="nowrap" align="right">&nbsp;</td>
                  <td><input type="submit" value="Insérer" /></td>
                </tr>
              </table>
              <input type="hidden" name="MM_insert" value="form1" />
          </form>
    et le code qui fait l'insertion est
    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
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
      $insertSQL = sprintf("INSERT INTO enseignant (code, code_gr, nom, prenom, grade, tele, fax, adresse, email, photo, service_membre, diplome, Enseignament_cours) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                           GetSQLValueString($_POST['code'], "text"),
                           GetSQLValueString($_POST['code_gr'], "int"),
                           GetSQLValueString($_POST['nom'], "text"),
                           GetSQLValueString($_POST['prenom'], "text"),
                           GetSQLValueString($_POST['grade'], "text"),
                           GetSQLValueString($_POST['tele'], "int"),
                           GetSQLValueString($_POST['fax'], "int"),
                           GetSQLValueString($_POST['adresse'], "text"),
                           GetSQLValueString($_POST['email'], "text"),
                           GetSQLValueString($_FILES['userfile']['name'], "file"),
                           GetSQLValueString($_POST['service_membre'], "text"),
                           GetSQLValueString($_POST['diplome'], "text"),
                           GetSQLValueString($_POST['Enseignament_cours'], "text"));
     
      mysql_select_db($database_informatique, $informatique);
      $Result1 = mysql_query($insertSQL, $informatique) or die(mysql_error());
     
      $insertGoTo = "../../reussite.html";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
      }
      header(sprintf("Location: %s", $insertGoTo));
    }

  7. #7
    Membre actif Avatar de juliens9
    Profil pro
    Développeur Web
    Inscrit en
    Mars 2007
    Messages
    192
    Détails du profil
    Informations personnelles :
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Mars 2007
    Messages : 192
    Points : 237
    Points
    237
    Par défaut
    Tu peux parler plus francais, car la j'ai du mal a saisir le sens de ta phrase et de ton probleme....

Discussions similaires

  1. [MySQL] Formulaire d'insertion+upload d'image
    Par belakhdarbts10 dans le forum PHP & Base de données
    Réponses: 8
    Dernier message: 29/07/2013, 09h05
  2. [DBExpress] Formulaire d'insertion (Base de donnée)
    Par Nadd dans le forum C++Builder
    Réponses: 14
    Dernier message: 12/07/2007, 10h22
  3. Formulaire et insertion d'image
    Par cadomalo dans le forum Access
    Réponses: 5
    Dernier message: 10/01/2006, 10h40
  4. [DW MX2004] formulaire d'insertion d'enregistrement
    Par jiraya_sama dans le forum Dreamweaver
    Réponses: 2
    Dernier message: 30/12/2004, 17h54
  5. Réponses: 7
    Dernier message: 12/10/2004, 16h43

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