-
Notifications
You must be signed in to change notification settings - Fork 0
/
addGiftCard.php
88 lines (83 loc) · 1.79 KB
/
addGiftCard.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
<?php
session_start();
ob_start();
?>
<html>
<body>
<?php
include('siteNavigator.php');
include "DB.php";
?>
<!--
addGiftCard.php
-->
<h3>Add a new gift card</h3>
<h2>just enter the necessary information below</h2>
<form method = "POST" action = "">
<table>
<tr>
<td>
Vendor Name:
</td>
<td>
<input type = "text" name = "name"/> (i.e. "McDonald's")
</td>
</tr>
<tr>
<td>
Vendor ID #:
</td>
<td>
<input type = "text" name = "id"/> (i.e. "9999")
</td>
</tr>
<tr>
<td>
Cost (in dollars):
</td>
<td>
<input type = "text" name = "cost"/>.00 (i.e. 50)
</td>
</tr>
<tr>
<td>
Percent Return (whole number):
</td>
<td>
<input type = "text" name = "percent" />% (i.e. 10)
</td>
</tr>
<tr><td><input type = "submit" value = "Submit" /></td></tr>
</table>
</form>
<?php
//pull inputs from post
$name = $_POST['name'];
$cost = $_POST['cost'];
$percent = $_POST['percent'];
$id = $_POST['id'];
$sanitizedName = mysqli_real_escape_string($db, $name);
$sanitizedCost = mysqli_real_escape_string($db,$cost);
$sanitizedPercent = mysqli_real_escape_string($db,$percent);
$sanitizedId = mysqli_real_escape_string($db,$id);
if ($cost < 0 or $percent < 0 or $percent > 100){
//error message
}else if (1 /*we have non-int values in int fields*/){
}else{ //go for it!
//ask if they're sure...but how?
$sure = false;
if ($sure){
$query = "INSERT INTO giftcards VALUES ('','$$sanitizedID','$sanitizedName','$sanitizedCost','$sanitizedPercent',1);";
$result = mysqli_query($db,$query);
echo "<h3> your insertion was successful! </h3>";
}else{
echo "<h3>canceled gift card insertion</h3>";
}
}
//sanitize inputs
//check for good inputs
//percent 0 < return < 100
//confirm submission?
//insert new row into gc table
//return success
?>