-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddSalesRecordProcess.php
86 lines (61 loc) · 2.88 KB
/
addSalesRecordProcess.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
<?php
// include connection to database
include 'db_connection.php';
// holds session data on this page
session_start();
// function to check correct input on addSalesRecordIndex.php form
function checkAddSalesRecordIndex(){
// for when the check button is clicked
if (isset($_POST['check'])){
// assigns values posted from html form to php variables
//session_start();
$memberID = $_POST['memberID'];
$numSold = $_POST['numSold'];
// checks both fields are not empty and consists of only digits
if ($memberID == "" || $numSold == "" || !ctype_digit($memberID) || !ctype_digit($numSold)){
echo "Member ID and Number of Sales must be digits only and not empty";
} else {
// connection to database
$conn = openConnection();
// query line to search for existance of the members ID within the database table
$search = "SELECT MemberID, Active FROM members WHERE MemberID = '$memberID'";
// if memberID is found the memberID and Active will be allocated to $result
$result = $conn->query($search);
// if the memberID is not found a message of non-existance is echoed
if($result->num_rows == 0){
echo "Member ID " , $memberID , " Does not exist.";
// if the memberID is found but is not active a no-active message is echoed
} else if($result->fetch_array()['Active'] == 0){
echo "Member ID " , $memberID , " is not currently active.";
// else memberID and numSold are held in session for next page and then next page open
} else {
$_SESSION['memberID'] = $memberID;
$_SESSION['numSold'] = $numSold;
header('Location: addSalesRecord.php');
}
}
}
}
// function to get members data from members DB table via memberID
function getMemberData(){
$memberID = $_SESSION['memberID'];
$conn = openConnection();
$search = "SELECT * FROM members WHERE MemberID = '$memberID'";
$result = $conn->query($search);
$member = $result->fetch_array();
return $member;
}
// function to set number of data entry rows on addSalesRecord.php form table via numSold
function numSoldRows(){
$numSold = $_SESSION['numSold'];
for ($i = 0; $i < $numSold; $i++){
echo '<tr>
<td><input id="prodID" name="prodID" type="text" placeholder = "Please Enter"></td>
<td><input id="price" name="price" type="text" value = "" readonly></td>
<td><input id="unit" name="unit" type="text" value = "" readonly></td>
<td><input id="quantity" name="quantity" type="text" placeholder = "Please Enter"></td>
<td><input id="subTotal" name="subTotal" type="text" value = "" readonly></td>
</tr>';
}
}
?>