-
Notifications
You must be signed in to change notification settings - Fork 1
/
recordserver.php
57 lines (48 loc) · 1.41 KB
/
recordserver.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
53
54
55
56
57
<?php
session_start();
$title = "";
$desc = "";
$field = "";
$id = 0;
$edit_state = false;
$db = mysqli_connect("localhost", "root", "", "experiment");
if (!$db) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
//insertion
if(isset($_POST['save'])){
$title = $_POST['title'];
$desc = $_POST['desc'];
$field = $_POST['field'];
$query = mysqli_query($db,
"INSERT INTO record (record_id, title, description, field)
VALUES (NULL, '".$title."', '".$desc."', '".$field."')");
$_SESSION['msg'] = "Experiment record saved.";
if($query){
header("location:records.php");
}else {
echo "Failed to add product. Contact the web developer for troubleshooting.";
exit();
}
}
//update
if(isset($_POST['update'])){
$title = $_POST['title'];
$desc = $_POST['desc'];
$field = $_POST['field'];
$id = $_POST['id'];
mysqli_query($db, "UPDATE record SET title='".$title."', description='".$desc."', field='".$field."' WHERE record_id=".$id);
$_SESSION['msg'] = "Experiment record updated!";
header('location:records.php');
}
//delete
if(isset($_GET['del'])){
$id = $_GET['del'];
mysqli_query($db, "DELETE FROM record WHERE record_id=".$id);
$_SESSION['msg'] = "Experiment record deleted!";
header('location:records.php');
}
//read
$results = mysqli_query($db, "SELECT * FROM record");
?>