ajoutcontact.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <html>
  2. <head>
  3. <title>Ajouter un contact</title>
  4. <link href="custom.css" rel="stylesheet">
  5. <meta name="viewport" content="width=device-width">
  6. </head>
  7. <body>
  8. <h1>Ajouter un contact</h1>
  9. <?php
  10. session_start();
  11. if (!isset($_SESSION['loggedin'])) {
  12. header("Location: login.php");
  13. exit;
  14. } else {
  15. $prenom = $_SESSION['first_name'];
  16. $nom = $_SESSION['last_name'];
  17. $profession = $_SESSION['profession'];
  18. $idsession = $_SESSION['ID'];
  19. }
  20. include_once 'class/sqlconnect.php';
  21. try {
  22. $conn = new PDO("mysql:host=$host;dbname=$dbname", $dbusername, $dbpassword);
  23. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  24. $stmt = $conn->prepare("SELECT ID FROM users WHERE username = :username");
  25. $stmt->bindParam(':username', $_SESSION['username']);
  26. $stmt->execute();
  27. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  28. $idsession = $result['ID'];
  29. } catch (PDOException $e) {
  30. echo "Error: " . $e->getMessage();
  31. }
  32. $conn = null;
  33. include 'class/sqlconnect.php';
  34. if(isset($_POST['submit'])){
  35. $prenom = $_POST['Prenom'];
  36. $nom = $_POST['Nom'];
  37. $poste = $_POST['Poste'];
  38. $poste = htmlentities($poste);
  39. $poste = str_replace("'", "\'", $poste);
  40. $mobile = $_POST['Mobile'];
  41. $entreprise = $_POST['IDEntreprise'];
  42. $sql = "INSERT INTO Contact (Prenom, Nom, Poste, Mobile, IDEntreprise, IDUser) VALUES ('$prenom', '$nom', '$poste', '$mobile', '$entreprise', '$idsession')";
  43. mysqli_query($conn, $sql);
  44. }
  45. ?>
  46. <a href="index.php">Revenir à l'accueil</a><br><br>
  47. <form method="post" action="">
  48. <table>
  49. <tr>
  50. <td>
  51. <label for="Prenom">Prénom :</label>
  52. </td>
  53. <td>
  54. <input type="text" name="Prenom" required>
  55. </td>
  56. </tr>
  57. <tr>
  58. <td>
  59. <label for="Nom">Nom :</label>
  60. </td>
  61. <td>
  62. <input type="text" name="Nom" required>
  63. </td>
  64. </tr>
  65. <tr>
  66. <td>
  67. <label for="Poste">Poste occupé :</label>
  68. </td>
  69. <td>
  70. <input type="text" name="Poste" >
  71. </td>
  72. </tr>
  73. <tr>
  74. <td>
  75. <label for="Mobile">Numéro de mobile :</label>
  76. </td>
  77. <td>
  78. <input type="text" name="Mobile" >
  79. </td>
  80. </tr>
  81. <tr>
  82. <td>
  83. <label for="Entreprise">Entreprise :</label>
  84. </td>
  85. <td>
  86. <select name="IDEntreprise">
  87. <?php
  88. $sql = "SELECT ID, NomSociete FROM Entreprise WHERE UserID =" . $idsession . ";";
  89. $result = mysqli_query($conn, $sql);
  90. while($row = mysqli_fetch_assoc($result)){
  91. echo "<option value='" . $row['ID'] . "'>" . $row['NomSociete'] . "</option>";
  92. }
  93. ?>
  94. </select>
  95. </td>
  96. </tr>
  97. </table>
  98. <br>
  99. <input type="submit" name="submit" value="Ajouter">
  100. </form>
  101. </body>
  102. </html>