-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlistUsers.php
executable file
·110 lines (84 loc) · 2.52 KB
/
listUsers.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
session_start();
if($_SESSION['Username'] == NULL){
header("location: logIn.php?user=");
}
?>
<!DOCTYPE html>
<?php
$currentpage="List Users";
include "pages.php";
?>
<html>
<head>
<title>List Users</title>
<?php include 'css.php';?>
</head>
<body>
<?php
// change the value of $dbuser and $dbpass to your username and password
include 'connectvars.php';
include 'header.php';
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
// query to select all information from supplier table
$loggedUser = $_SESSION['Username'];
$query = "SELECT F.Followed, U.NumPics FROM FinFollow F, FinUser U WHERE Follower='$loggedUser' AND U.Username=F.Followed";
// Get results from query
$result = mysqli_query($conn, $query);
if (!$result) {
die("Query to show fields from table failed");
}
// get number of columns in table
$fields_num = mysqli_num_fields($result);
echo '<div class="row">';
echo '<div class="col s12 m12">';
echo '<div class="card grey lighten-1">';
echo '<div class="card-content black-text">';
echo "<h1>You are following:</h1>";
echo "<table class='striped' id='t01' border='1'><tr>";
for($i=0; $i<$fields_num; $i++) {
$field = mysqli_fetch_field($result);
echo "<td><b>$field->name</b></td>";
// printing table headers
}
if ($_SESSION['Username'] != NULL){
// echo "<td><b>Following</b></td>";
}
echo "</tr>\n";
$na = $_SESSION['Username'];
while($row = mysqli_fetch_row($result)) {
echo "<tr>";
// $row is array... foreach( .. ) puts every element
// of $row to $cell variable
foreach($row as $cell)
echo "<td>$cell</td>";
if ($_SESSION['Username'] != NULL){
echo "<form action='' method='POST'>";
// echo "<td><input name = 'follow' type='submit' value='Follow Me'/></td>";
echo "</form>";
}
else{
}
echo "</tr>\n";
}
if (isset($_POST['follow'])) {
// btnfollow
$query = "INSERT INTO FinFollow (Follower,Followed) VALUES ('$na','$') ";
if(mysqli_query($conn, $query)){
echo "<p>Record added successfully.</p>";
} else{
echo "ERROR: Could not able to execute $query. " . mysqli_error($conn);
}
}
echo "</div>";
echo "</div>";
echo "</div>";
echo "</div>";
mysqli_free_result($result);
mysqli_close($conn);
?>
</body>
</html>