-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmySQLweb.php
More file actions
180 lines (141 loc) · 4.12 KB
/
mySQLweb.php
File metadata and controls
180 lines (141 loc) · 4.12 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
#The homework is completed only by Melanie Zhao without consulting any other students except Instructor and TAs
<html>
<head>
<title> CS377 MySQL Web client</title>
</head>
<body>
<H3>
<HR>
Answer to the query
<HR>
</H3>
<P>
<UL>
<?php
$conn = mysqli_connect("holland.mathcs.emory.edu","cs377", "abc123");
if (mysqli_connect_errno()) # ----------- check connection error
{
printf("Connect failed: %s\n", mysqli_connect_error());
exit(1);
}
if ( ! mysqli_select_db($conn, "spjDB") ) # Select spjDB
{
printf("Error: %s\n", mysqli_error($conn));
exit(1);
}
$sname = $_POST['sname'];
$pname = $_POST['pname'];
$jname = $_POST['jname'];
$scity = $_POST['scity'];
$pcity = $_POST['pcity'];
$jcity = $_POST['jcity'];
$query = "select supplier.sname as 'Supplier Name' ,supplier.city as 'Supplier City', part.pname as 'Part Name',part.city as 'Part City',
proj.jname as 'Project Name',proj.city as 'Project City', qty as 'Quantity Shipped'
from spj,supplier,part,proj
where spj.jnum=proj.jnum
and spj.snum=supplier.snum
and spj.pnum=part.pnum";
if (!empty($sname)){
for ( $i = 0; $i < strlen($sname); $i++ )
{
if ( $sname[$i] == '*' )
$sname[$i] = '%';
if ( $sname[$i] == '?')
$sname[$i] = '_';
}
$query .=" and supplier.sname like '\\$sname'";
}
if (!empty($pname)){
for ( $i = 0; $i < strlen($pname); $i++ )
{
if ( $pname[$i] == '*' )
$pname[$i] = '%';
if ( $pname[$i] == '?')
$pname[$i] = '_';
}
$query .=" and part.pname like '\\$pname'";
}
if(!empty($jname)){
for ( $i = 0; $i < strlen($jname); $i++ )
{
if ( $jname[$i] == '*' )
$jname[$i] = '%';
if ( $jname[$i] == '?')
$jname[$i] = '_';
}
$query .=" and proj.jname like '\\$jname'";
}
if(!empty($scity)){
for ( $i = 0; $i < strlen($scity); $i++ )
{
if ( $scity[$i] == '*' )
$scity[$i] = '%';
if ( $scity[$i] == '?')
$scity[$i] = '_';
}
$query .=" and supplier.city like '\\$scity'";
}
if(!empty($pcity)){
for ( $i = 0; $i < strlen($pcity); $i++ )
{
if ( $pcity[$i] == '*' )
$pcity[$i] = '%';
if ( $pcity[$i] == '?')
$pcity[$i] = '_';
}
$query .=" and part.city like '\\$pcity'";
}
if(!empty($jcity)){
for ( $i = 0; $i < strlen($jcity); $i++ )
{
if ( $jcity[$i] == '*' )
$jcity[$i] = '%';
if ( $jcity[$i] == '?')
$jcity[$i] = '_';
}
$query .=" and proj.city like '\\$jcity'";
}
print("<UL><TABLE bgcolor=\"#FFEEEE\" BORDER=\"5\">\n");
print("<TR> <TD><FONT color=\"blue\"><B><PRE>\n");
print( $query ); # echo the query
print("</PRE></B></FONT></TD></TR></TABLE></UL>\n");
print("<P><HR><P>\n");
if ( ! ( $result = mysqli_query($conn, $query)) ) # Execute query
{
printf("Error: %s\n", mysqli_error($conn));
exit(1);
}
print("<UL>\n");
print("<TABLE bgcolor=\"lightyellow\" BORDER=\"5\">\n");
$printed = false;
while ( $row = mysqli_fetch_assoc( $result ) )
{
if ( ! $printed )
{
$printed = true; # Print header once...
print("<TR bgcolor=\"lightcyan\">\n");
foreach ($row as $key => $value)
{
print ("<TH>" . $key . "</TH>"); # Print attr. name
}
print ("</TH>\n");
}
print("<TR>\n");
foreach ($row as $key => $value)
{
print ("<TD>" . $value . "</TD>");
}
print ("</TR>\n");
}
print("</TABLE>\n");
print("</UL>\n");
print("<P>\n");
mysqli_free_result($result);
mysqli_close($conn);
?>
</UL>
<P>
<HR>
<HR>
<HR>
<HR>