First let me say, I am very green when it comes to PHP...
Okay, here is the URL:
http://www.olevetpossehideout.com/test/populate-list.php
As you can see, it is for testing purposes.
Now here is the code (which I shortened to save time), forgive me if it is not very tidy:
<?php
$user = "username";
$host = "localhost";
$password = "password";
$dbName = "databasename";
/* make connection to database */
mysql_connect($host, $user, $password) OR DIE( "Unable to connect
to database");
mysql_select_db($dbName) or die(mysql_error()); //did you forget this line?
$sql = "SELECT DISTINCT Name FROM Teams";
$result = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT
?>
<form action="process.php" method="post" name="vote">
<table border="0" cellpadding="2" cellspacing="0" align="center" width="400">
<tr>
<td colspan="2" align="center"><b><font size="4">Top 25 poll</font></b><br> Please select all spots. <br>All teams are listed in alphabetical order.<br> No duplicates will be allowed!!!</td>
</tr>
<tr>
<td>1.</td>
<td>
<select name="one">
<option>Who is #1?</option>
<?php
while ($row = mysql_fetch_array($result)) {
echo "<option value=\"" . $row['Name'] . "\">" . $row['Name'] . "</option>\n";
}
?>
</td>
</tr>
<tr>
<td>2.</td>
<td>
<select name="two">
<option>Choose #2:</option>
<?php
$sql = "SELECT DISTINCT Name FROM Teams";
$result = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT
while ($row = mysql_fetch_array($result)) {
echo "<option value=\"" . $row['Name'] . "\">" . $row['Name'] . "</option>\n";
}
?>
</td>
</tr>
<tr>
<td>3.</td>
<td>
<select name="three">
<option>Choose #3:</option>
<?php
$sql = "SELECT DISTINCT Name FROM Teams";
$result = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT
while ($row = mysql_fetch_array($result)) {
echo "<option value=\"" . $row['Name'] . "\">" . $row['Name'] . "</option>\n";
}
?>
</td>
</tr>
<tr>
<td>4.</td>
<td>
<select name="four">
<option>Choose #4:</option>
<?php
$sql = "SELECT DISTINCT Name FROM Teams";
$result = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT
while ($row = mysql_fetch_array($result)) {
echo "<option value=\"" . $row['Name'] . "\">" . $row['Name'] . "</option>\n";
}
?>
</td>
</tr>
<tr>
<td>5.</td>
<td>
<select name="five">
<option>Choose #5:</option>
<?php
$sql = "SELECT DISTINCT Name FROM Teams";
$result = mysql_query($sql) or die(mysql_error() . "<br>$sql"); //use the or die(...) part ONLY IN DEVELOPMENT
while ($row = mysql_fetch_array($result)) {
echo "<option value=\"" . $row['Name'] . "\">" . $row['Name'] . "</option>\n";
}
?>
</td>
</tr>
<tr><td colspan="2"> </td></tr>
<tr>
<td colspan="2" align="center">
</select>
<input type="Submit">
</td>
</tr>
</table>
</form>
It seems to work fine...but...
Where I need help is:
1. Does this appear to be coded correctly for using multiple drop down lists?
2. How do I prevent someone from submitting the same team twice (I thought SELECT DISTINCT would do it, but I think I am wrong)? and...
3. How do I get what is submitted to go to a database?