I have the following to code to update the database based on checkbox selection.
while($row = mysql_fetch_array($result)){
$rebootpol = $row['reboot policy'];
$host = $row['host'];
$environment = $row['environment'];
$patchpol = $row['patch policy'];
echo "<tr><td>" . $host . "</td><td>" . $environment . "</td><td><input type='checkbox' name='envdev[]' value='" . $host . "'/></td><td><input type='checkbox' name='envprd[]' value='" . $host . "'/></td><td>" . $reboot . "</td><td><input type='checkbox' name='id[]' value='" . $host . "'/></td></tr>";
}
echo "</tbody></table><input type='submit' value='submit'></form>";
if(gettype($_POST['id'])=="array"){
foreach($_POST['id'] as $val){
$id_c = $val;
$query2 = "UPDATE hosts SET reboot = 'Yes' where host='".$id_c."'";
$result2 = mysql_query($query2);
if($result2 === false) {
die(mysql_error());
}
echo "Reboot updated for Host " .$id_c. " is updated. <br>";
How can I port the same for dropdown code like below.
while($row = mysql_fetch_array($result)){
$rebootpol = $row['reboot policy'];
$host = $row['host'];
$environment = $row['environment'];
$patchpol = $row['patch policy'];
echo "<tr><td>" . $host . "</td>
<td>
<input type='hidden' name='envdev[]' value='" . $host . "'>
<select name='select'><option value='0' selected='selected'>Select any</option>
<option value='DEV/QA/TEST'>DEV/QA/TEST</option>
<option value='PROD/STAGE'>PROD/STAGE</option>
</select>
</td><td>" . $environment . "</td>
How can I keep track of what was selected and update the database? For the checkbox I was using the Value field but that is used in dropdowns.