Hi PHPBuilder Community,
I am new to PHP, and maybe this belongs in the newbie section, but I figured it related to mySQL and PHP so it should go here. If not let me know. Here is my situation though:
I have a mySQL table with the following fields:
Course_ID - INT - Autoincrement
CoursePrefix - VARCHAR (6)
CourseNumber - VARCHAR (3)
CourseSection - VARCHAR (3)
innoDB engine
I need to create a drop down list for an html form based on the records in that table. I have 3 drop downs one for each field except Course_ID.
I thought I setup my PHP code correctly but when I click the drop down list that renders there are just blank spots were the values should be listed...
Here is my source code, any errors you see? Thanks for reading this post!
<html>
<head>
<title>Workshop Request Form</title>
<link rel="stylesheet" href="test.css" type="text/css" />
</head>
<body style="font-family: verdana; font-size: 11px;">
<?php
$username = "myusername";
$password = "mypassword";
$db = "thedbnamehere";
$link = mysql_connect(localhost,$username,$password);
@ mysql_select_db($db) or die("Could not connect to the desired database.");
$cpquery = "SELECT DISTINCT courseprefix FROM course";
$cnquery = "SELECT DISTINCT coursenumber FROM course";
$csquery = "SELECT DISTINCT coursesection FROM course";
$cpresult = mysql_query($cpquery) or die(mysql_error());
$cnresult = mysql_query($cnquery) or die(mysql_error());
$csresult = mysql_query($csquery) or die(mysql_error());
?>
<h2>WORKSHOP REQUEST FORM</h2>
<p>Faculty, please fill out the form below and click submit to request a workshop. You will recieve a confirmation
<br>once the request has been processed.</p>
<form name="input" action="mail.php" method="post">
<p>Requestor's First Name:</p>
<input size="30" type="text" name="firstname">
<p>Requestor's Last Name:</p>
<input size="30" type="text" name="lastname">
<p>Course Prefix:
<select name="cprefix">
<!-- Drop down -->
<?php
while($row = mysql_fetch_array($cpresult)){
echo '<option value="' .$row['CoursePrefix']. '">'. $row['CoursePrefix']. '</option>' ;
}
?>
<option value="cprefix">Course Prefix</option>
</select>
Course Number:
<select name="cnumber">
<!-- Drop down -->
<?php
while($row = mysql_fetch_array($cnresult)){
echo '<option value="'.$row['CourseNumber'].'">'.$row['CourseNumber'].'</option>';
}
?>
<option value="cnumber">Course Number</option>
</select>
Course Section:
<select name="csection">
<!-- Drop down -->
<?php
while($row = mysql_fetch_array($csresult)){
echo '<option value="'.$row['CourseSection'].'">'.$row['CourseSection'].'</option>';
}
echo'</select>';
?>
<option value="csection">Course Section</option>
</select></p>
<p>Workshop: </p>
<select name="workshops">
<!-- Drop down -->
<option value="workshops">Available Workshops</option>
</select>
<p>Expected number of students:</p>
<input size="2" maxlength="2" type="text" name="snumber">
<p>Comments: </p>
<textarea rows="6" cols="50">Other comments.</textarea>
<p><input type="submit" value="Submit" name="submit"><p>
</form>
</body>
</html>