ajoutentreprise.php 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <html>
  2. <head>
  3. <title>Ajouter une entreprise</title>
  4. <link href="custom.css" rel="stylesheet">
  5. <meta name="viewport" content="width=device-width">
  6. </head>
  7. <?php
  8. session_start();
  9. if (!isset($_SESSION['loggedin'])) {
  10. header("Location: login.php");
  11. exit;
  12. }
  13. if (isset($_SESSION['username'])) {
  14. $prenom = $_SESSION['first_name'];
  15. $nom = $_SESSION['last_name'];
  16. $profession = $_SESSION['profession'];
  17. $idsession = $_SESSION['ID'];
  18. include_once 'class/sqlconnect.php';
  19. try {
  20. $conn = new PDO("mysql:host=$host;dbname=$dbname", $dbusername, $dbpassword);
  21. $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  22. $stmt = $conn->prepare("SELECT ID FROM users WHERE username = :username");
  23. $stmt->bindParam(':username', $_SESSION['username']);
  24. $stmt->execute();
  25. $result = $stmt->fetch(PDO::FETCH_ASSOC);
  26. $idsession = $result['ID'];
  27. } catch (PDOException $e) {
  28. echo "Error: " . $e->getMessage();
  29. }
  30. $conn = null;
  31. }
  32. include("class/sqlconnect.php");
  33. ?>
  34. <body>
  35. <a href="index.php">Revenir à l'accueil</a><br><br>
  36. <h1>Ajouter une entreprise</h1>
  37. <form action="ajoutentreprise.php" method="post">
  38. <table>
  39. <tr>
  40. <td>
  41. <label for="NomSociete">Nom de la société :</label>
  42. </td>
  43. <td>
  44. <input type="text" id="NomSociete" name="NomSociete" required>
  45. </td>
  46. </tr>
  47. <tr>
  48. <td>
  49. <label for="Adresse">Adresse postale de la société : (facultatif)</label>
  50. </td>
  51. <td>
  52. <input type="text" id="Adresse" name="Adresse">
  53. </td>
  54. </tr>
  55. <tr>
  56. <td>
  57. <label for="NumeroTel">Numéro de téléphone de la société : (format 0102030405)</label>
  58. </td>
  59. <td>
  60. <input type="text" id="NumeroTel" name="NumeroTel" pattern="0[0-9]{9}">
  61. </td>
  62. </tr>
  63. </table>
  64. <br>
  65. <input type="submit" name="submit" value="Ajouter">
  66. </form>
  67. <?php
  68. if(isset($_POST["submit"])) {
  69. $NomSociete = $_POST["NomSociete"];
  70. $Adresse = $_POST["Adresse"];
  71. $Adresse = htmlentities($Adresse);
  72. $Adresse = str_replace("'", "\'", $Adresse);
  73. $NumeroTel = $_POST["NumeroTel"];
  74. $StatutEntretien = "2";
  75. $sql = "INSERT INTO Entreprise (NomSociete, Adresse, NumeroTel, StatutEntretien, UserID)
  76. VALUES ('$NomSociete', '$Adresse', '$NumeroTel', '$StatutEntretien', '$idsession')";
  77. $result = mysqli_query($conn, $sql);
  78. if($result) {
  79. echo "La nouvelle entreprise a été ajoutée avec succès.";
  80. } else {
  81. echo "Erreur : " . $sql . "<br>" . mysqli_error($conn);
  82. }
  83. }
  84. ?>