-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpledge.php
More file actions
74 lines (69 loc) · 2.6 KB
/
pledge.php
File metadata and controls
74 lines (69 loc) · 2.6 KB
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
<html>
<?php
require 'head.php';
?>
<body>
<?php
require 'navbar.php';
$querystring = $_SERVER['QUERY_STRING'];
$projectid = str_replace("projectid=", "", $querystring);
$sqlfindmaxfund = "SELECT maxfund from project where projectid = ".$projectid;
$result_maxfund = $conn->query($sqlfindmaxfund);
while ($fund_array=mysqli_fetch_assoc($result_maxfund))
{
$maxfund = $fund_array["maxfund"];
}
$sqlfindpledged = "SELECT sum(pledgeamount) as pledged from pledge where projectid = ".$projectid;
$result_pledged = $conn->query($sqlfindpledged);
while ($pledge_array=mysqli_fetch_assoc($result_pledged))
{
$pledgedsofar = $pledge_array["pledged"];
}
?>
<div class="signin-form">
<div class="container">
<form class="form-signin" action="createpledge.php" method="post" name="pledge-form" id="pledge-form" onsubmit="return validateForPledge(<?php echo $maxfund.",".$pledgedsofar ?>)">
<h2 class="form-signin-heading">Support this project</h2><hr />
<div class="form-group">
<input type="text" class="form-control" placeholder="Pledge Amount" name="pledgeamount" required/>
<div id="pledgeerror" class="showerror"> </div>
</div>
<div class="form-group">
<?php
$sql = "SELECT ccn FROM creditcardowner where email='".$email."'";
$result = $conn->query($sql);
echo "<select name='ccn' required class='form-control' onchange=document.getElementById('selectedcard').value=this.options[this.selectedIndex].text>";
$count = 0;
echo "<option value='' > Select Card </option>";
while ($ccn_array=mysqli_fetch_assoc($result))
{
$count += 1;
echo "<option value=$count >".htmlspecialchars($ccn_array["ccn"])."</option>";
}
echo "</select>";
?>
<input type="hidden" name="selectedcard" id="selectedcard" value="" />
<input type="hidden" name="projectid" id="projectid" value="<?php echo $projectid ?>" />
</div>
<div class="form-group">
<button type="submit" class="btn btn-default" name="btn-pledge">
<span class="glyphicon glyphicon-log-in"></span> Create Pledge
</button>
<button type="reset" class="btn btn-default"> Clear
</button>
</div>
</form>
<script type="text/javascript">
function validateForPledge(maxfund,pledgedsofar) {
flag = true;
totalpledgeamount = parseInt(document.forms["pledge-form"]["pledgeamount"].value) + pledgedsofar;
allowedpledge = maxfund - pledgedsofar;
if(totalpledgeamount > maxfund){
flag = false;
document.getElementById('pledgeerror').innerHTML="Sorry you cannot pledge more than "+allowedpledge;
}
return flag;
}
</script>
</body>
</html>