-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.php
More file actions
74 lines (60 loc) · 2.33 KB
/
Copy pathserver.php
File metadata and controls
74 lines (60 loc) · 2.33 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
71
72
73
74
<?php
$name = "";
$Message = "";
$time= date("m/d/y H:i");
$notifcations = array();
$posts = array();
$i=0;
//connect to the database
$db = mysqli_connect('localhost','root','','namelist');
// pull post from database
$sql= "Select * FROM list ORDER BY time DESC";
$result = mysqli_query($db, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
$posts['name'][$i]=$row["name"];
$posts['message'][$i]=$row["message"];
$posts['time'][$i]=$row["time"];
$i++;
}
}
//if the post button is clicked
if(isset($_POST['Post'])){
$name = mysqli_real_escape_string($db, $_POST['name']);
$Message = mysqli_real_escape_string($db, $_POST['Message']);
// ensure that form fields are filled properly
if (empty($name)){
array_push($notifcations,"Username is required");
}
if (empty($Message)){
array_push($notifcations,"Message is required");
}
// If ther are no error, save user to database
if (count($notifcations) == 0) {
$sql = "INSERT INTO list (name, message, time) VALUES ('$name','$Message','$time')";
mysqli_query($db, $sql);
echo "<script type='text/javascript'>alert('Post Sent');</script>";
header('location: index.php');
}
}
//if the delete button is clicked
if(isset($_POST['del'])){
$name = mysqli_real_escape_string($db, $_POST['name']);
// ensure that form fields are filled properly
if (empty($name)){
array_push($notifcations,"Username is required");
}
$sql= "Select * FROM list WHERE name= '$name'";
$result = mysqli_query($db, $sql);
if (mysqli_num_rows($result) > 0) {
$sql = "Delete From list where name = '$name'";
mysqli_query($db, $sql);
echo "<script type='text/javascript'>alert('Post Deleted');</script>";
header('location: index.php');
}
else{
array_push($notifcations,"User not found");
}
}
?>