1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
Dismiss Notice
Welcome to our Education website, plz like our page facebook to support us. Thank You and wish you good navigation

Charger un fichier en PHP

abdelouafiOct 4, 2016

    1. abdelouafi

      abdelouafi Administrator Staff Member

      Messages:
      165
      Likes Received:
      7
      Trophy Points:
      18
      Joined
      Sep 13, 2016
      code source du fichier cvs.php :
      Code:
      <html>
          <head>
              <style>
                  body{
                      font:14pt monospace;
                  }
              </style>
          </head>
          <body>
          <div align="center">
              <form name="fo" method="post" action="cvs.php" enctype="multipart/form-data">
               
                  <input type="file" name="cvs"><br>
                  <input type="submit" name="valider" value="Charger le CVS">
               
              </form>
              <?php
                  if(isset($_POST["valider"])){
                      mysql_connect("localhost","mastergi","mastergi") or die("Erreur serveur!");
                      mysql_select_db("mabase");
                      $fp=fopen($_FILES["cvs"]["tmp_name"],"r+");
                      fgets($fp,200);
                      while(!feof($fp)){
                          $str=fgets($fp,200);
                          $tab=explode(";",$str);
                          $requette="insert into matable(id,date,nom,prenom) values(\"".$tab[0]."\",\"".$tab[1]."\",\"".$tab[2]."\",\"".$tab[3]."\")";
                          if($tab[0]!="")
                          mysql_query($requette);
                       
                      }
                      echo "<font size='5' color='green'>CVS chargé avec succès!</font>";
                  }
              ?><br><br>
              <a href="db.php">Voir les enregistrements</a>
          </div>
          </body>
      </html>
      code php du fichier db.php :

      Code:
      <?php
          $nom=$_POST["nom"];
          $prenom=$_POST["prenom"];
          $valider=$_POST["valider"];
          $iden=$_GET["id"];
          $supprimer=$_GET["supprimer"];
          if($supprimer=="ok"){
              mysql_connect("localhost","mastergi","mastergi") or die("Erreur serveur!");
              mysql_select_db("mabase") or die("Erreur DB!");
              mysql_query("delete from matable where id=\"$iden\"");
          }
          if(isset($valider)){
              mysql_connect("localhost","mastergi","mastergi") or die("Erreur serveur!");
              mysql_select_db("mabase") or die("Erreur DB!");
              mysql_query("insert into matable(nom,prenom) values(\"$nom\",\"$prenom\")");
          }
      ?>
      <html>
          <head>
              <style>
                  td{
                      font:10pt verdana;
                      color:#555555;
                  }
              </style>
          </head>
          <body>
              <form name="fo" method="post" action="db.php">
                  Nom <input type="text" name="nom"><br>
                  Prénom <input type="text" name="prenom"><br>
                  <input type="submit" name="valider" value="Valider"><br>
              </form><br>
              <a href="cvs.php">Charger un CVS</a>
              <br>
              <table width="100%" border="0" cellspacing="2" cellpadding="0">
              <?php
              mysql_connect("localhost","mastergi","mastergi") or die("Erreur serveur!");
              mysql_select_db("mabase") or die("Erreur DB!");
                  $req=mysql_query("select * from matable order by id DESC");
                  while($tab=mysql_fetch_array($req)){
                      $id=$tab["id"];
                      $date=$tab["date"];
                      $nom=$tab["nom"];
                      $prenom=$tab["prenom"];
                      ?>
                      <tr><td width="100%" bgcolor="#DDDDDD" height="20" onMouseOver="this.style.backgroundColor='#BBBBBB'"  onMouseOut="this.style.backgroundColor='#DDDDDD'">
                      <table width="100%" border="0" cellspacing="2" cellpadding="4">
                      <tr>
                          <td width="10%" height="20"><?php echo $id?>
                          </td>
                          <td width="40%" height="20"><?php echo $date?>
                          </td>
                          <td width="15%" height="20"><?php echo "<b>$nom</b>"?>
                          </td>
                          <td width="15%" height="20"><?php echo "<b>$prenom</b>"?>
                          </td>
                          <td width="10%" height="20"><a href="db.php?supprimer=ok&id=<?php echo $id?>" onClick="return confirm('Voulez vous supprimer l\'élement N <?php echo $id?>?')">Supprimer</a>
                          </td>
                          <td width="10%" height="20"><a href="modif.php?modifier=ok&id=<?php echo $id?>">Modifier</a>
                          </td>
                          </tr>
                      </table></td></tr>
                      <?php
                  }
              ?>
              </table>
          </body>
      </html>
      La modification : modif.php
      Code:
      <?php
          $nom=$_POST["nom"];
          $prenom=$_POST["prenom"];
          $valider=$_POST["valider"];
          $idmodif=$_POST["idmodif"];
          $iden=$_GET["id"];
          $modifier=$_GET["modifier"];
          if($modifier=="ok"){
          mysql_connect("localhost","mastergi","mastergi") or die("Erreur serveur!");
              mysql_select_db("mabase") or die("Erreur DB!");
              $req=mysql_query("select * from matable where id=\"$iden\"");
              while($tab=mysql_fetch_array($req)){
                  $id=$tab["id"];
                  $date=$tab["date"];
                  $nom=$tab["nom"];
                  $prenom=$tab["prenom"];
              }
              }
           
              if(isset($valider)){
              mysql_connect("localhost","mastergi","mastergi") or die("Erreur serveur!");
              mysql_select_db("mabase") or die("Erreur DB!");
              mysql_query("update matable set nom=\"$nom\",prenom=\"$prenom\" where id=\"$idmodif\"");
          ?>
              <script language="javascript">
                  document.location.href("db.php");
              </script>
          <?php
              exit();
              }
      ?>
      <html>
          <head>
          </head>
          <body>
          <form name="fo" method="post" action="modif.php">
                  Nom <input type="text" name="nom" value="<?php echo $nom?>"><br>
                  Prénom <input type="text" name="prenom" value="<?php echo $prenom?>"><br>
                  <input type="hidden" name="idmodif" value="<?php echo $iden ?>">
                  <input type="submit" name="valider" value="Modifier"><br>
              </form>
          </body>
      </html>
       

      Attached Files:

      Last edited: Dec 24, 2016
      Loading...

Share This Page

Share