-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunsub.php
67 lines (59 loc) · 1.33 KB
/
unsub.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
58
59
60
61
62
63
64
65
66
67
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<?php
if(isset($_GET["email"])){
// echo "h";
showlist($_GET["email"]);
}
?>
<body>
<?php
if(!isset($_GET["email"])){
echo "
enter the email
<form action=\"unsub.php\" method=\"GET\">
<input type=\"text\" name=\"email\">
<input type=\"submit\" value=\"Submit\">
</form>
";
}
?>
</body>
</html>
<?php
function showlist($email=null){
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "asgn3";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "select topic from subs where user_email='$email'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// output data of each row
echo "select from topics to unsubscribe";
echo "<form action=\"unsubs.php\" method=\"GET\" >";
echo "<input type=text name=email value=$email><br>";
while($row = $result->fetch_assoc()) {
$topic = trim($row['topic']);
echo "<input type=checkbox name=category[] value=$topic>";
echo $topic;
echo "<br>";
}
echo "<input type=\"submit\" value=\"submit\">";
echo "</form>";
}
else {
echo "you have not subscribed to any topic";
}
$conn->close();
}
?>