Q:

Php script to display checkbox and update database

I have the following code to query the database for fields hostname, notifier and print it out in a table.

$host = "test.xxxx.com";
$user = "host";
$pass = "xxxx";
$db = "hosts";

$connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

mysql_select_db($db) or die ("Unable to select database!");

$owner = $_GET['owner'];
$query = "SELECT `host`,`notifier` FROM `hosts` where `owner`='$owner'";

$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

echo "<form method='post' action='#'>";
$len = mysql_num_fields($result);
$tempString =  "<html><body><table border='2'><tr>";
for($i=0; $i<$len; $i++)
{$tempString = $tempString.'<th>'.mysql_fetch_field($result)->name.'</th>';}
while ($row=mysql_fetch_array($result, MYSQL_ASSOC))
{$tempString = $tempString.'</tr><tr>';
foreach($row as $cell)
{$tempString = $tempString.'<td>'.(($cell==null) ? '<input type="checkbox">Null field</input>' : $cell).'</td>';}
}
 $tempString = $tempString.'</td></tr></table></body></html>';
 echo $tempString;
 echo "</tbody></table><input type='submit' value='submit'></form>";

How can I include the following code to update my database table with a "Y" based on the checked value with value in the check box?
 $cell = N;
 if(isset($_POST['cell']) and $_POST['cell']==1) {
  $cell = Y;
}
   $query = mysql_query("UPDATE `hosts`.`hosts` SET `notifier`='$cell' WHERE `host`='$name';") or die ("Error in query: $query. ".mysql_error());

A:

Using <th> inside <tr> works - that creates a table header

You've got two basic choices to get the checkbox into your html. One is to create the html via the echo process you're using. Your if statement would go into the foreach loop to create the checkbox if the value from your db is null. You'll want to name each checkbox using the id= element in your html. Each checkbox will require a unique id, so that you can reference it later on (e.g. id="CB_nnn", where nnn is a value from 000 to whatever is your max). 
You then either add all of the id's to your submit button statement, or you write some javascript to gather all of the unique id's together to then send the data back.
It may be simpler, although it starts harder, to package your data from your db as a JSON stream or as an XML stream and manage it for the user via javascript. That will give you a better separation of your data model (from the db) and the View portion of your app. This would be a simple application of the MVC - Model/View/Controller pattern. 
 this approach would allow you to have a portion of your javascript solely dedicated to creating the User Interface and a separate set of services for managing the data movement between your php code and the UI.
The following code will create a table, header and evaluate each field for presence of a null value returned by the DB engine (mysql in this case).  The ternary operator (the "?" operator) will either display the value of the returned data or will display a checkbox with the text "null field" next to it. 

$len = mysql_num_fields($resultSet);
$tempString =  "<html><body><table border='2'><tr>";
for($i=0; $i<$len; $i++)
 {$tempString = $tempString.'<th>'.mysql_fetch_field($resultSet)->name.'</th>';}
 while ($row=mysql_fetch_array($resultSet, MYSQL_ASSOC))
 {$tempString = $tempString.'</tr><tr>';
 foreach($row as $cell)
 {$tempString = $tempString.'<td>'.(($cell==null) ? '<input type="checkbox">Null field</input>' : $cell).'</td>';}
 }
 $tempString = $tempString.'</td></tr></table></body></html>';
 echo $tempString;

