-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathmyActivitiesSession.php
99 lines (80 loc) · 2.86 KB
/
myActivitiesSession.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
<?php require 'headerTab.php'?>
<body>
<div class="container">
</br>
</br>
</br>
<form id='login' action="myActivitiesSession.php" method='post' accept-charset='UTF-8'>
<div class="panel panel-primary">
<div class="panel-heading">Send Money</div>
<div class="panel-body">
<div class="form-group">
<label for='ToUserName' >To UserName*:</label>
<input type='text' name='ToUserName' id='ToUserName' maxlength="50" required />
<label for='Amount' >Amount:</label>
<input type='text' name='Amount' id='Amount' maxlength="50" required />
<input type="hidden" name="fromUserName" value="<?= $_SESSION['userName'];?>" />
<input type='submit' class="btn btn-default" name='Submit' id='submit' value='Send' />
</div>
</div>
</div>
</form>
<h1> List of Activities</h1>
<table class="table table-bordered">
<thead>
<tr>
<td> transaction Key </td>
<td> from </td>
<td> To</td>
<td> Amount</td>
</tr>
</thead>
<tbody>
<?php
//Database Authentication
require("DBInfo.inc");
$userName = $_SESSION['userName'];
//connect to database
$connect = mysqli_connect($hostDB, $userDB,$passwordDB,$databaseDB);
if(mysqli_connect_errno()){
die(" cannot connect to database ". mysqli_connect_error());
}
//Add new Activitiy
if(!empty($_POST['fromUserName']) and !empty($_POST['ToUserName'])) {
$query ="insert into activities(fromUserName,ToUserName,Amount)
values ('".$_POST['fromUserName'] ."','".$_POST['ToUserName'] ."',".$_POST['Amount'] .")" ;
$result= mysqli_query($connect,$query);
if (!$result){
die(' Error cannot run query');
}
}
// get user activities
if( !empty($userName)) {
$query ="select * from activities where fromUserName='". $userName ."' or ToUserName='". $userName ."'" ;
$result= mysqli_query($connect,$query);
if (!$result){
die(' Error cannot run query');
}
$userInfo=array();
$loginInUser=null;
while ($row= mysqli_fetch_assoc($result)) {
$rowColor ="class='success'";
if($row["fromUserName"]==$userName){
$rowColor ="class='danger'";
}
echo " <tr ". $rowColor .">";
echo " <td>". $row["transactionKey"] ." </td>";
echo " <td>". $row["fromUserName"] ." </td>";
echo " <td>". $row["ToUserName"]."</td>";
echo " <td>". $row["Amount"]."</td>";
echo " </tr>";
}
mysqli_free_result($result);
}
mysqli_close($connect);
?>
</tbody>
</table>
</div>
</body>
<?php require 'footerTab.php'?>