commit 67941b40341186a6c0055b86a80e5d665c16124b
parent 500270b3071d48c4d1140223d0a932fc27a47b1d
Author: MoiBaguette <[email protected]>
Date: Mon, 10 Apr 2023 17:56:54 +0200
connect class
Diffstat:
4 files changed, 49 insertions(+), 50 deletions(-)
diff --git a/Connect.php b/Connect.php
@@ -0,0 +1,22 @@
+<?php
+class Connect
+{
+ protected string $servername = "86.92.67.21";
+ protected string $username = "friedel";
+ protected string $password = "hailiwa";
+ protected string $dbname = "wap2";
+ protected mysqli $conn;
+ function __construct(){
+ // Create connection
+ $this->conn = mysqli_connect($this->servername, $this->username, $this->password, $this->dbname);
+ // Check connection
+ if (!$this->conn)
+ {
+ die("Connection failed: " . mysqli_connect_error());
+ }
+ }
+ function getConn(){
+ return $this->conn;
+ }
+}
+?>
+\ No newline at end of file
diff --git a/crud_user.php b/crud_user.php
@@ -7,6 +7,7 @@
</head>
<?php
include "navbar.php";
+ include "Connect.php";
if(!in_array(1, $_SESSION['permissions'])){
header('Location: dashboard.php');
exit;
@@ -50,16 +51,8 @@
</form>
</div>
<?php
- $servername = "86.92.67.21";
- $username = "friedel";
- $password = "hailiwa";
- $dbname = "wap2";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
+ $connect = new Connect;
+ $conn = $connect->getConn();
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$errors = array(); // initialize an empty array to store errors
diff --git a/searchdata.php b/searchdata.php
@@ -1,12 +1,11 @@
-<html>
-
-<head>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
-</head>
<?php
-include "navbar.php";
+ include "navbar.php";
+ include "Connect.php";
?>
-
+<html>
+ <head>
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
+ </head>
<body>
<form class="d-flex" action="searchdata.php" method="get">
<input class="form-control me-2" type="date" name="date-begin" placeholder="Date begin" aria-label="Date begin">
@@ -14,18 +13,9 @@ include "navbar.php";
<input class="form-control me-2" type="text" name="station" placeholder="Search" aria-label="Search">
<button class="btn btn-outline-success" type="submit">Search</button>
</form>
-
<?php
- $servername = "86.92.67.21";
- $username = "friedel";
- $password = "hailiwa";
- $dbname = "wap2";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
+ $connect = new Connect;
+ $conn = $connect->getConn();
$sql = "SELECT station_name, date_time, validated, temperature FROM weather_data";
if (isset($_GET['date-begin']) && $_GET['date-begin'])
@@ -43,6 +33,7 @@ include "navbar.php";
if (isset($_GET['station']) && $_GET['station']) {
$stmt->bind_param('d', $_GET['station']);
}
+
$stmt->execute();
$result = $stmt->get_result();
@@ -76,5 +67,4 @@ include "navbar.php";
}
?>
</body>
-
</html>
\ No newline at end of file
diff --git a/searchuser.php b/searchuser.php
@@ -1,26 +1,19 @@
+<?php
+ include "navbar.php";
+ include "Connect.php";
+?>
<html>
- <head>
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
- </head>
+ <head>
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
+ </head>
+<body>
+ <form class="d-flex" action="searchuser.php" method="post">
+ <input class="form-control me-2" type="search" name="search" placeholder="Search" aria-label="Search">
+ <button class="btn btn-outline-success" type="submit">Search</button>
+</form>
<?php
- include "navbar.php";
- ?>
- <body>
- <form class="d-flex" action="searchuser.php" method="post">
- <input class="form-control me-2" type="search" name="search" placeholder="Search" aria-label="Search">
- <button class="btn btn-outline-success" type="submit">Search</button>
- </form>
- <?php
- $servername = "86.92.67.21";
- $username = "friedel";
- $password = "hailiwa";
- $dbname = "wap2";
- // Create connection
- $conn = mysqli_connect($servername, $username, $password, $dbname);
- // Check connection
- if (!$conn) {
- die("Connection failed: " . mysqli_connect_error());
- }
+ $connect = new Connect;
+ $conn = $connect->getConn();
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['search'])) {
$search = $_POST['search'];