-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest2.php
More file actions
185 lines (131 loc) · 3.83 KB
/
Copy pathrequest2.php
File metadata and controls
185 lines (131 loc) · 3.83 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
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<?php session_start(); ?>
<!DOCTYPE HTML>
<html>
<?php
include 'stuhead.php';
?>
<head>
<title>Request</title>
<meta name="description" content="website description" />
<meta name="keywords" content="website keywords, website keywords" />
<meta http-equiv="content-type" content="text/html; charset=windows-1252" />
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<fieldset>
<legend align="center" ><h2> REQUEST FORM </h2></legend>
<center>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
<H3>
LAB: <input type="radio" name="labid" value="ECE1" /> ECE lab1
<input type="radio" name="labid" value="ECE2" /> ECE lab2
<input type="radio" name="labid" value="ECE3" checked/> ECE lab3<br>
<br>
<br>
<?php
$servername = "localhost";
$username = "root";
$password = "time.org";
$dbname = "component_distribution";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM component";
$result = $conn->query($sql);
echo "<br><center> Components </center> ";
if ($result->num_rows > 0) {
echo "<br>";
while($row = $result->fetch_assoc()){
echo "<h4> " .$row['name']. "<h4> <input type='number' name=".$row['compId']." min='0' placeholder='0 if not required'> <br>";
//echo "DURATION IN HOURS: <input type='number' name='number[]' min='0'> <br>";
echo "<br>";
}
} else {
echo "RECORD NOT FOUND";
exit;
}
?>
</H3>
<input type="submit">
</form>
</fieldset>
</center>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
$servername = "localhost";
$username = "root";
$password = "time.org";
$dbname = "component_distribution";
// Create $connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// set parameters and execute
$sql1 = "SELECT MAX(RequestNo) FROM request";
$result1 = $conn->query($sql1);
$row1 = $result1->fetch_assoc();
$requestno = $row1['MAX(RequestNo)'] + 1;
$sql3 = "SELECT * FROM component ";
$result3 = $conn->query($sql3);
if ($result3->num_rows > 0) {
echo "<br><br>";
while($row = $result3->fetch_assoc()){
//echo "<h4> " .$row['name']. "</h4>";
if($_POST[$row['compId']] > 0)
{
$stmt = $conn->prepare("INSERT INTO request (rollno, labId, RequestNo, status, compId, number) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bind_param("siiiii", $rollno, $labid, $requestno, $status, $compid, $number);
// set parameters and execute
$labid=$_POST["labid"];
$status=0;
$compid=$row['compId'];
$number=$_POST[$row['compId']];
$stmt->execute();
}
}
}
else {
echo "RECORD NOT FOUND";
exit;
}
require 'phpmailer/PHPMailerAutoload.php';
$hello = "hello";
$mail = new PHPMailer();
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPDebug = 0;
$mail->Username = 'rohit29041998@gmail.com';
$mail->Password = 'rohit@895';
$mail->setFrom('rohit29041998@gmail.com', 'admin');
$mail->addAddress('rohit29041998@gmail.com');
$mail->Subject = 'Request for components';
$a = "The Student " .$rollno. " requested for these comp:\n COMPID Quantity \n";
$sql4 = "SELECT * FROM request WHERE RequestNo=".$requestno."";
$result4 = $conn->query($sql4);
if ($result4->num_rows > 0) {
while($row = $result4->fetch_assoc()){
$a .= " ".$row["compId"]. " ".$row["number"]."\n";
}
$mail->Body = $a;
}
if ($mail->send())
{ echo "Mail sent";
}
$conn->close();
}
?>
<script>
function selects()
{
document.getElementById("srequest").className = "selected";
}
</script>
</body>
</html>