Hi guys,
I am having problems filling a drop down box with data from a column in a MySQL table.
If anyone is able to see a problem with my coding could they please post where the problems are, and possibly how i would go about fixing it.
Thanks,
Ben
The problem code is below:
<html>
<head>
<title>PHP Testing Page</title>
</head>
<body>
<h1>Online Student Enrolment System</h1>
<?php
//connecting to the MySQL database
$link = mysql_connect("localhost","root","")or die('Unable to connect to SQL server: ' . mysql_error());
mysql_select_db ('team y') or die('Could not select database');
$course = @('SELECT CourseCode, CourseCode FROM link');
if (!$course) {
exit('<p> Unable to obtain course list from database.</p>');
}
$major = @('SELECT MajorCode, MajorName FROM link');
if (!$major) {
exit('<p> Unable to obtain major list from database.</p>');
}
?>
<form action ="search.php" method="post">
<p>View Courses that match your relevant criteria</p>
<label>By Course Name:
<select name ="crse" size="1">
<option selected value = " ">Any Course</option>
<?php
while ($course = mysql_fetch_array($course)) {
$crse = $course['CourseCode'];
$crsename = htmlspecialchars ($course['CourseName']);
echo "<option value=$crse>$crsename</option>\n";
}
?>
</select></label>
<p></p>
</p>
<label>By Major:
<select name ="mjr" size="1">
<option selected value = " ">Any Major</option>
<?php
while ($major = mysql_fetch_array($major)) {
$mjr = $major['MajorCode'];
$mjrname = htmlspecialchars ($major['MajorName']);
echo "<option value=$mjr>$majrname</option>\n";
}
?>
</select></label><br />
<p></p>
<input type = "submit" value = "Search" />
</form>
</body>
</html>