modifcontact.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. <?php
  7. session_start();
  8. if (!isset($_SESSION['loggedin'])) {
  9. header("Location: login.php");
  10. exit;
  11. }
  12. ?>
  13. </head>
  14. <body>
  15. <h1>Modifier un contact</h1>
  16. <?php
  17. include('class/sqlconnect.php');
  18. $id = $_GET['ID'];
  19. $sql = "SELECT * FROM Contact WHERE ID = '$id'";
  20. $result = $conn->query($sql);
  21. $row = $result->fetch_assoc();
  22. ?>
  23. <a href="index.php">Revenir à l'accueil</a><br><br>
  24. <form action="modifcontact.php" method="post">
  25. <table>
  26. <tr>
  27. <td>
  28. <input type="hidden" name="ID" value="<?php echo $id; ?>">
  29. <label>Prénom :</label>
  30. </td>
  31. <td>
  32. <input type="text" name="Prenom" value="<?php echo $row['Prenom']; ?>">
  33. </td>
  34. </tr>
  35. <tr>
  36. <td>
  37. <label>Nom :</label>
  38. </td>
  39. <td>
  40. <input type="text" name="Nom" value="<?php echo $row['Nom']; ?>">
  41. </td>
  42. <tr>
  43. <td>
  44. <label>Poste :</label>
  45. </td>
  46. <td>
  47. <input type="text" name="Poste" value="<?php echo $row['Poste']; ?>">
  48. </td>
  49. </tr>
  50. <tr>
  51. <td>
  52. <label>Entreprise :</label>
  53. </td>
  54. <td>
  55. <select name="IDEntreprise">
  56. <?php
  57. $sql = "SELECT * FROM Entreprise";
  58. $result = $conn->query($sql);
  59. while ($entreprise = $result->fetch_assoc()) {
  60. if ($entreprise['ID'] == $row['IDEntreprise']) {
  61. echo "<option value='" . $entreprise['ID'] . "' selected>" . $entreprise['NomSociete'] . "</option>";
  62. } else {
  63. echo "<option value='" . $entreprise['ID'] . "'>" . $entreprise['NomSociete'] . "</option>";
  64. }
  65. }
  66. ?>
  67. </select>
  68. </td>
  69. </tr>
  70. <tr>
  71. <td>
  72. <label>Numéro de mobile (format 0102030405) :</label>
  73. </td>
  74. <td>
  75. <input type="text" name="Mobile" pattern="0[0-9]{9}" value="<?php echo $row['Mobile']; ?>">
  76. </td>
  77. </tr>
  78. <tr>
  79. <td>
  80. <label>Adresse e-mail :</label>
  81. </td>
  82. <td>
  83. <input type="email" name="Mail" value="<?php echo $row['Mail']; ?>">
  84. </td>
  85. </tr>
  86. </table>
  87. <br>
  88. <input type="submit" name="submit" value="Enregistrer les modifications">
  89. </form>
  90. <?php
  91. if(isset($_POST['submit'])) {
  92. $id = $_POST['ID'];
  93. $prenom = $_POST['Prenom'];
  94. $nom = $_POST['Nom'];
  95. $poste = $_POST['Poste'];
  96. $poste = htmlentities($poste);
  97. $poste = str_replace("'", "\'", $poste);
  98. $entreprise = $_POST['IDEntreprise'];
  99. $mobile = $_POST['Mobile'];
  100. $mail = $_POST['Mail'];
  101. $sql = "UPDATE Contact SET Prenom='$prenom', Nom='$nom', Poste='$poste', IDEntreprise='$entreprise', Mobile='$mobile', Mail='$mail' WHERE ID='$id'";
  102. if ($conn->query($sql) === TRUE) {
  103. echo "Le contact a été modifié avec succès";
  104. header("refresh:1; url=infocontact.php?ID=".$id);
  105. } else {
  106. echo "Erreur lors de la modification : " . $conn->error;
  107. }
  108. }
  109. ?>