-
Notifications
You must be signed in to change notification settings - Fork 1
/
markasConfirmed.php
50 lines (41 loc) · 1.71 KB
/
markasConfirmed.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
<?php
$read=$_POST['read'];
$servername = "localhost"; // host which has established our computer.If the database is on a sever, then this should change accordinly
$username = "root"; // username and the password of the mysql sever
$password = "";
$dbname = "SamajaSathkara";
$conn = new mysqli($servername,$username,$password,$dbname); // making the connection with mysql
if ($conn->connect_error){ // check whether the connection is correctly established or not
die("Connection failed: " . $conn->connect_error);
}
$sql = 'SELECT ProjectID,amount FROM Donation Where id='.$read; //reading things from the table
$result = $conn->query($sql);
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()){
$projectid=$row["ProjectID"];
$amount=$row["amount"];
}
}
$sql = 'SELECT completed,estimatedprojectcost,raised FROM Projects Where projectid="'.$projectid.'"'; //reading things from the table
$result = $conn->query($sql);
if ($result->num_rows > 0){
while($row = $result->fetch_assoc()){
$completed=$row["completed"];
$estimatedprojectcost=$row["estimatedprojectcost"];
$raised=$row["raised"];
}
}
$raised=$raised+$amount;
if ($estimatedprojectcost<=$raised){
$completed=1;
}
echo 'newraised='.$raised;echo '<br>';
echo 'new completed='.$completed;
$sql ='UPDATE Projects SET raised='.$raised.' Where projectid="'.$projectid.'"';
$conn->query($sql);
$sql ='UPDATE Projects SET completed='.$completed.' Where projectid="'.$projectid.'"';
$conn->query($sql);
$sql ='UPDATE Donation SET approved=true WHERE id='.$read;
$conn->query($sql);
$conn->close();
?>