modifcontact.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <html>
  2. <head>
  3. <title>Modifier un contact</title>
  4. <link href="custom.css" rel="stylesheet">
  5. <meta name="viewport" content="width=device-width">
  6. </head>
  7. <body>
  8. <h1>Modifier un contact</h1>
  9. <?php
  10. include('class/sqlconnect.php');
  11. $id = $_GET['ID'];
  12. $sql = "SELECT * FROM Contact WHERE ID = '$id'";
  13. $result = $conn->query($sql);
  14. $row = $result->fetch_assoc();
  15. ?>
  16. <form action="modifcontact.php" method="post">
  17. <table>
  18. <tr>
  19. <td>
  20. <input type="hidden" name="ID" value="<?php echo $id; ?>">
  21. <label>Prénom :</label>
  22. </td>
  23. <td>
  24. <input type="text" name="Prenom" value="<?php echo $row['Prenom']; ?>">
  25. </td>
  26. </tr>
  27. <tr>
  28. <td>
  29. <label>Nom :</label>
  30. </td>
  31. <td>
  32. <input type="text" name="Nom" value="<?php echo $row['Nom']; ?>">
  33. </td>
  34. <tr>
  35. <td>
  36. <label>Poste :</label>
  37. </td>
  38. <td>
  39. <input type="text" name="Poste" value="<?php echo $row['Poste']; ?>">
  40. </td>
  41. </tr>
  42. <tr>
  43. <td>
  44. <label>Entreprise :</label>
  45. </td>
  46. <td>
  47. <select name="IDEntreprise">
  48. <?php
  49. $sql = "SELECT * FROM Entreprise";
  50. $result = $conn->query($sql);
  51. while ($entreprise = $result->fetch_assoc()) {
  52. if ($entreprise['ID'] == $row['IDEntreprise']) {
  53. echo "<option value='" . $entreprise['ID'] . "' selected>" . $entreprise['NomSociete'] . "</option>";
  54. } else {
  55. echo "<option value='" . $entreprise['ID'] . "'>" . $entreprise['NomSociete'] . "</option>";
  56. }
  57. }
  58. ?>
  59. </select>
  60. </td>
  61. </tr>
  62. <tr>
  63. <td>
  64. <label>Numéro de mobile :</label>
  65. </td>
  66. <td>
  67. <input type="text" name="Mobile" value="<?php echo $row['Mobile']; ?>">
  68. </td>
  69. </tr>
  70. </table>
  71. <br>
  72. <input type="submit" name="submit" value="Enregistrer les modifications">
  73. </form>
  74. <?php
  75. if(isset($_POST['submit'])) {
  76. $id = $_POST['ID'];
  77. $prenom = $_POST['Prenom'];
  78. $nom = $_POST['Nom'];
  79. $poste = $_POST['Poste'];
  80. $entreprise = $_POST['IDEntreprise'];
  81. $mobile = $_POST['Mobile'];
  82. $sql = "UPDATE Contact SET Prenom='$prenom', Nom='$nom', Poste='$poste', IDEntreprise='$entreprise', Mobile='$mobile' WHERE ID='$id'";
  83. if ($conn->query($sql) === TRUE) {
  84. echo "Le contact a été modifié avec succès";
  85. header("refresh:1; url=infocontact.php?ID=".$id);
  86. } else {
  87. echo "Erreur lors de la modification : " . $conn->error;
  88. }
  89. }
  90. ?>