-
Notifications
You must be signed in to change notification settings - Fork 0
/
query.php
81 lines (68 loc) · 2.12 KB
/
query.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
<?php
// Connect to database
function connect_db () {
$db = "localhost";
$username = "root";
$password = "BabyBibo1117";
if (!($link = mysql_connect($db, $username, $password))) {
return ("");
}
else {
return ($link);
}
}
// Begin process
if ($_POST) {
// Retrieve HTTP variables
$id_num = $_POST['id_number'];
// Connect to database server
if (!($link = connect_db())) {
echo "connect to database error";
exit(1);
}
// Begin querying
// Select database & set charset
mysql_select_db("umunc_v2");
mysql_query("SET CHARACTER SET utf8");
mysql_query("SET NAMES utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
// Get delegate's name from database
$query = "select del_name from delegate_all where id_num = '$id_num'";
if (!($result = mysql_query($query))) {
//print ("query failed " . mysql_error());
echo "query failed";
exit(1);
}
// Get row from SQL resource
$del_name = mysql_fetch_row($result);
//echo "name is: " . $del_name[0];
// Get delegate's system using the name
$query = "select system from delegate_alloc where del_name = '$del_name[0]'";
if (!($result = mysql_query($query))) {
//print ("query failed " . mysql_error());
echo "query failed";
exit(1);
}
// Get row from SQL resource
$system = mysql_fetch_row($result);
$sys = $system[0];
//echo "system is: " . $sys;
// Get delegate's allocation using the name
$query = "select representation, pos_original, pos_chn, name_original, name_chn, del_name from delegate_alloc where del_name = '$del_name[0]'";
if (!($result = mysql_query($query)))
{
// print ("query failed " . mysql_error());
echo "query failed";
exit(1);
}
// Get row from SQL resource
$alloc = mysql_fetch_row($result);
// Return the allocation if success, encoded with json
echo json_encode(array("system" => $sys, "alloc" => $alloc));
}
else {
// Return error
echo "no http post";
}
?>