-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathmyActivities1.php
115 lines (91 loc) · 3.12 KB
/
myActivities1.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
111
112
113
114
115
<?php require 'headerTab.php'?>
<body>
<div class="container">
</br>
</br>
</br>
<form id='login' action="myActivities1.php?userToken=<?= $_GET['userToken'];?>" 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='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");
//connect to database
$connect = mysqli_connect($hostDB, $userDB,$passwordDB,$databaseDB);
if(mysqli_connect_errno()){
die(" cannot connect to database ". mysqli_connect_error());
}
$userToken = $_GET['userToken'];
//get user name from token
$query ="select userName from login where userToken='" . $userToken ."'" ;
$result= mysqli_query($connect,$query);
if (!$result){
die(' Error cannot run query');
}
$userName=null;
while ($row= mysqli_fetch_assoc($result)) {
$userName= $row["userName"];
break; // to be save
}
//======================================
//Add new Activitiy
if(!empty($userName) and !empty($_POST['ToUserName'])) {
$query ="insert into activities(fromUserName,ToUserName,Amount)
values ('".$userName ."','".$_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'?>