The following script is supposed to update my database, the environment column with the selected value for the drop down menu. Right now, the last host is getting a value of 0. What am I doing wrong? It seems like I am not able to track the hosts and the value that was selected.
while($row = mysql_fetch_array($result)){
$host = $row['host'];
$environment = $row['environment'];
echo "<tr><td>" . $host . "</td>
<td><select name='id[".$host."]'><option value='Null'>Select any</option>
<option value='DEV/QA/TEST'>DEV/QA/TEST</option>
<option value='PROD/STAGE'>PROD/STAGE</option>
</select></td>
<td>" . $environment . "</td></tr>"; }
echo "</tbody></table><input type='submit' value='submit'></form>";
if (gettype($_POST['id'])=="array") {
foreach($_POST['id'] as $host => $val){
$id_c = $val;
if ($val != 'Null') {
$query1 = "UPDATE hosts SET environment = '$val' where host='$host'";
$result1 = mysql_query($query1);
if($result1 === false) {
die(mysql_error());
}
echo "Environment for Host " .$host. " is updated. <br>";
}}}
Updated with working script.