-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.php
More file actions
71 lines (49 loc) · 1.68 KB
/
Copy pathprocess.php
File metadata and controls
71 lines (49 loc) · 1.68 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
session_start();
// Create connection
$con = new mysqli("localhost","root","","post");
// Check connection
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
$total = 0;
$update = false;
$id=0;
$name = '';
$description = '';
if(isset($_POST['save'])){
$post = $_POST['post'];
$description = $_POST['description'];
$query = mysqli_query($con, "INSERT INTO post (name, description) VALUE ('$post', '$description')");
$_SESSION['massage'] = "Recode has been saved !";
$_SESSION['msg_type'] = "primary";
header("location: post.php?result=true");
}
//delete post
if(isset($_GET['delete'])){
$id = $_GET['delete'];
$query = mysqli_query($con, "DELETE FROM post WHERE id=$id");
$_SESSION['massage'] = "Recode has been Delete !";
$_SESSION['msg_type'] = "danger";
header("location: post.php");
}
if(isset($_GET['edit'])){
$id = $_GET['edit'];
$update = true;
$result = mysqli_query($con, "SELECT * FROM post WHERE id=$id");
if( mysqli_num_rows($result) == 1){
$row = $result->fetch_assoc();
$name = $row['name'];
$description = $row['description'];
}
}
if(isset($_POST['update'])){
$id = $_POST['id'];
$post = $_POST['post'];
$description = $_POST['description'];
$query = mysqli_query($con, "UPDATE post SET name='$post', description='$description' WHERE id='$id'");
$_SESSION['massage'] = "Recode has been Update !";
$_SESSION['msg_type'] = "success";
header("location: post.php");
}
?>