Making sure user made a selection
Posted: Fri Mar 21, 2008 1:27 pm
I know that this is something basic but nothing that I have been trying seems to work. I have a form that has a "Ratings" dropdown menu for each Competency. How can I test on the action page so that the user didn't forget to make a selection from one of the dropdown menus. Thank you.
code---------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><basefont face="Arial">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<Link Rel=stylesheet TYPE="text/css" href="Styles.css">
<title>Assign Ratings</title>
</head>
<body>
<?php
// include configuration file
include('config.php');
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query
$query = "SELECT CompetencyID, CompetencyName, SkilledDefinition
FROM LTRCOMPETENCY";
$result = mysql_query($query) or die("ERROR: $query.".mysql_error());
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// if records are present
if (mysql_num_rows($result) > 0) {
//$row = mysql_fetch_object($result);
// get CompetencyID and Rating
$CompetencyID = $row->CompetencyID;
$Rating = $row->Rating;
echo "<form method = post action = 'processRatings.php'>";
// print them one after another
echo "<div align='center'>";
echo "<table cellpadding=10 border=1 id=reg width=780>";
echo "<tr>";
echo "<td><strong> </strong></td>";
echo "<td><strong>Competency</strong></td>";
echo "<td><strong>Performance Criteria</strong></td>";
echo "<td><strong>Rating</strong></td>";
echo "</tr>";
//set a counter
if (mysql_num_rows($result) > 0) {
$i=1;
while ($row = mysql_fetch_object($result)) {
//echo "<input type = radio name = aid value = '".$row->aid."'>".$row->atitle."</input><br />";
echo "<tr>";
echo "<td>".$i++."</td>";
echo "<td>".$row->CompetencyName."</td>";
echo "<td align='left'>".$row->SkilledDefinition."</td>";
echo "<input type=hidden name=CompetencyID[] value = '".$row->CompetencyID."'>";
echo "<td>
<select name='Rating[]'>
<option value=0>Please make a selection</option>
<option value=1>1 - Not at all</option>
<option value=2>2 - To some extent</option>
<option value=3>3 - To a moderate extent</option>
<option value=4>4 - To a considerable extent</option>
<option value=5>5 - To a great extent</option>
</select>
</td>";
echo "</tr>";
}
}
echo "<tr>";
echo "<td colspan=4><input type = submit name = submit value=Submit></td>";
echo "</tr>";
echo "</table>";
echo "</div>";
echo '</form>';
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>
</body>
</html>
code---------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><basefont face="Arial">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<Link Rel=stylesheet TYPE="text/css" href="Styles.css">
<title>Assign Ratings</title>
</head>
<body>
<?php
// include configuration file
include('config.php');
// open connection
$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");
// select database
mysql_select_db($db) or die ("Unable to select database!");
// generate and execute query
$query = "SELECT CompetencyID, CompetencyName, SkilledDefinition
FROM LTRCOMPETENCY";
$result = mysql_query($query) or die("ERROR: $query.".mysql_error());
// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());
// if records are present
if (mysql_num_rows($result) > 0) {
//$row = mysql_fetch_object($result);
// get CompetencyID and Rating
$CompetencyID = $row->CompetencyID;
$Rating = $row->Rating;
echo "<form method = post action = 'processRatings.php'>";
// print them one after another
echo "<div align='center'>";
echo "<table cellpadding=10 border=1 id=reg width=780>";
echo "<tr>";
echo "<td><strong> </strong></td>";
echo "<td><strong>Competency</strong></td>";
echo "<td><strong>Performance Criteria</strong></td>";
echo "<td><strong>Rating</strong></td>";
echo "</tr>";
//set a counter
if (mysql_num_rows($result) > 0) {
$i=1;
while ($row = mysql_fetch_object($result)) {
//echo "<input type = radio name = aid value = '".$row->aid."'>".$row->atitle."</input><br />";
echo "<tr>";
echo "<td>".$i++."</td>";
echo "<td>".$row->CompetencyName."</td>";
echo "<td align='left'>".$row->SkilledDefinition."</td>";
echo "<input type=hidden name=CompetencyID[] value = '".$row->CompetencyID."'>";
echo "<td>
<select name='Rating[]'>
<option value=0>Please make a selection</option>
<option value=1>1 - Not at all</option>
<option value=2>2 - To some extent</option>
<option value=3>3 - To a moderate extent</option>
<option value=4>4 - To a considerable extent</option>
<option value=5>5 - To a great extent</option>
</select>
</td>";
echo "</tr>";
}
}
echo "<tr>";
echo "<td colspan=4><input type = submit name = submit value=Submit></td>";
echo "</tr>";
echo "</table>";
echo "</div>";
echo '</form>';
}
else {
// no
// print status message
echo "No rows found!";
}
// free result set memory
mysql_free_result($result);
// close connection
mysql_close($connection);
?>
</body>
</html>