
Untitled
By: a guest on
Apr 29th, 2012 | syntax:
None | size: 1.94 KB | hits: 22 | expires: Never
<?php
$dbhost = "sql.njit.edu";
$dbuser = "kdm9_proj";
$dbpass = "vhI5Wj7P";
$dbh = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to connect to MySQL");
$dbname = "kdm9_proj";
$selected = mysql_select_db($dbname,$dbh);
$courseandtime = mysql_query ("SELECT SESSION.SID, Location, Time, MaxEnrollment, COUNT(REGISTERED.SID) FROM SESSION, REGISTERED WHERE REGISTERED.CID=('$_POST[CID]') AND SESSION.Time=('$_POST[Time]') AND SESSION.SID = REGISTERED.SID");
echo "Sessions available for ";
echo $_POST[CID];
echo " at ";
echo $_POST[Time];
echo ":";
echo "<BR><BR>";
echo "<table border='1'>
<tr>
<th>Session</th>
<th>Location</th>
<th>Time</th>
<th>Max Enrollment</th>
<th>Currently Enrolled</th>
</tr>";
while($row = mysql_fetch_array($courseandtime))
{
echo "<tr>";
echo "<td>" . $row['SID'] . "</td>";
echo "<td>" . $row['Location']. "</td>";
echo "<td>" . $row['Time'] . "</td>";
echo "<td>" . $row['MaxEnrollment'] . "</td>";
echo "<td>" . $row['COUNT(REGISTERED.SID)'] . "</td>";
echo "</tr>";
}
echo "</table>";
if($courseandtime) { $max_e = $courseandtime['MaxEnrollment']; $current_e = $courseandtime['COUNT(REGISTERED.SID)']; }
if ($current_e < $max_e) {
echo "
<form action='register-exec.php' method='post'>
<label>Time: $_POST[Time]</label><br>
<input type='hidden' value='$Time' /><br><br>
<label>Student ID:</label><br>
<input type='text' name='SUCID' id='SUCID' /><br><br>
<label>CID: $_POST[CID]</label><br>
<input type='hidden' name='CID' id='CID' /><br><br>
<label>SID: $row['SID']</label><br>
<input type='hidden' name='SID' id='SID' value='$courseandtime[\"SID\"]' />
<button type='submit'>Register</button>
</form>
";
}
else {
echo 'Sorry, were full!';
}
mysql_close($dbh);
?>