-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathca.php
executable file
·52 lines (48 loc) · 1.98 KB
/
ca.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
<?php
require "config.inc.php";
$con = mysql_connect($glHost, $glUsername, $glPassword);
mysql_select_db($glDatabase,$con);
$sHostel = $_GET['hostel'];
$sRoom = (int)$_GET['room'];
if($sRoom == 0)
die("Room does not exist");
$xml = new DOMDocument();
$xml -> load("hostelList.xml");
$hostels = $xml -> getElementsByTagName('hostel');
foreach($hostels as $hostel)
if($hostel -> getAttribute('name') == $sHostel) {
foreach($hostel -> getElementsByTagName('maxperroom') as $max) {
$maxpr = $max -> nodeValue;
}
foreach($hostel -> getElementsByTagName('noofrooms') as $nor) {
$maxRooms = $nor -> nodeValue;
}
}
/*$query = "SELECT nperroom, totalrooms FROM " . $glTablePref . "list WHERE hname = '$sHostel'";
$result = mysql_query($query, $con);
$myrow = mysql_fetch_array($result);
$maxpr = $myrow['nperroom'];
$maxRooms = $myrow['totalrooms'];*/
if($sRoom > $maxRooms)
die("Room does not exist");
$query = "SELECT rollno, name FROM " . $glTablePref . "namelist WHERE hostel = '$sHostel' AND roomno = '$sRoom'";
$result = mysql_query($query, $con);
$sNum = mysql_num_rows($result);
echo "Maximum of " . $maxpr . " students can stay in each room in " . $sHostel . " hostel<br />";
echo "Currently " . $sNum . " student(s) have registered to stay in " . $sHostel . " room number " . $sRoom . ".<br />";
if($sNum == $maxpr) {
die("So you need to choose another room");
}
else if($sNum > 0) {
echo "<hr />The following students have registered to stay in the room so far:<br><ul align='left'>";
while($myrow = mysql_fetch_array($result)) {
echo "<li>" . $myrow['rollno'] . " : " . $myrow['name'] . "</li>";
}
echo "</ul><hr />";
}
echo "You can opt to stay in this room.";
echo '<form method="post" action="./?v=application">';
echo "<input type='hidden' name='roomno' value='". $sRoom . "' />";
echo "<input type='submit' name='msg' value='Register to stay in $sHostel hostel, room number $sRoom' /></form>";
mysql_close($con);
?>