-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.php
52 lines (46 loc) · 1.5 KB
/
server.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
ini_set('user_agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36');
session_start();
$servername = "localhost";
$sqlusername = "root";
$sqlpassword = "";
$dbname = "happyplace";
// Create connection
$db = new mysqli($servername, $sqlusername, $sqlpassword, $dbname);
// Check connection
if ($db->connect_error) {
die("Connection failed: " . $db->connect_error);
}
// initialize variables
$prename = "";
$lastname = "";
$place_id = "";
$id = 0;
$update = false;
if (isset($_POST['save'])) {
$prename = $_POST['prename'];
$lastname = $_POST['lastname'];
$place_id = $_POST['place_id'];
mysqli_query($db, "INSERT INTO apprentices (prename, lastname,place_id) VALUES ('$prename', '$lastname','$place_id')");
echo mysqli_error($db);
$_SESSION['message'] = " saved";
header('location: index.php');
}
if (isset($_POST['update'])) {
$id = $_POST['id'];
$prename = $_POST['prename'];
$lastname = $_POST['lastname'];
$place_id = $_POST['place_id'];
$uppdate = false;
mysqli_query($db, "UPDATE apprentices SET prename='$prename', lastname='$lastname', place_id='$place_id' WHERE id=$id");
echo mysqli_error($db);
$_SESSION['message'] = "updated!";
header('location: index.php');
}
if (isset($_GET['del'])) {
$id = $_GET['del'];
mysqli_query($db, "DELETE FROM apprentices WHERE id=$id");
echo mysqli_error($db);
$_SESSION['message'] = "deleted!";
header('location: index.php');
}