modifcontact.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <html>
  2. <head>
  3. <title>Modifier un contact</title>
  4. </head>
  5. <body>
  6. <h1>Modifier un contact</h1>
  7. <?php
  8. include('class/sqlconnect.php');
  9. $id = $_GET['ID'];
  10. $sql = "SELECT * FROM Contact WHERE ID = '$id'";
  11. $result = $conn->query($sql);
  12. $row = $result->fetch_assoc();
  13. ?>
  14. <form action="modifcontact.php" method="post">
  15. <input type="hidden" name="ID" value="<?php echo $id; ?>">
  16. <label>Prénom :</label>
  17. <input type="text" name="Prenom" value="<?php echo $row['Prenom']; ?>">
  18. <br>
  19. <label>Nom :</label>
  20. <input type="text" name="Nom" value="<?php echo $row['Nom']; ?>">
  21. <br>
  22. <label>Poste :</label>
  23. <input type="text" name="Poste" value="<?php echo $row['Poste']; ?>">
  24. <br>
  25. <label>Entreprise :</label>
  26. <select name="IDEntreprise">
  27. <?php
  28. $sql = "SELECT * FROM Entreprise";
  29. $result = $conn->query($sql);
  30. while ($entreprise = $result->fetch_assoc()) {
  31. if ($entreprise['ID'] == $row['IDEntreprise']) {
  32. echo "<option value='" . $entreprise['ID'] . "' selected>" . $entreprise['NomSociete'] . "</option>";
  33. } else {
  34. echo "<option value='" . $entreprise['ID'] . "'>" . $entreprise['NomSociete'] . "</option>";
  35. }
  36. }
  37. ?>
  38. </select>
  39. <br>
  40. <label>Numéro de mobile :</label>
  41. <input type="text" name="Mobile" value="<?php echo $row['Mobile']; ?>">
  42. <br>
  43. <input type="submit" name="submit" value="Enregistrer les modifications">
  44. </form>
  45. <?php
  46. if(isset($_POST['submit'])) {
  47. $id = $_POST['ID'];
  48. $prenom = $_POST['Prenom'];
  49. $nom = $_POST['Nom'];
  50. $poste = $_POST['Poste'];
  51. $entreprise = $_POST['IDEntreprise'];
  52. $mobile = $_POST['Mobile'];
  53. $sql = "UPDATE Contact SET Prenom='$prenom', Nom='$nom', Poste='$poste', IDEntreprise='$entreprise', Mobile='$mobile' WHERE ID='$id'";
  54. if ($conn->query($sql) === TRUE) {
  55. echo "Le contact a été modifié avec succès";
  56. header("refresh:1; url=infocontact.php?ID=".$id);
  57. } else {
  58. echo "Erreur lors de la modification : " . $conn->error;
  59. }
  60. }
  61. ?>