I have been trying to get this to work for a while now and cant figure it out. I am trying to display records from a database where the condition is the field "completed" is " ". After they are displayed I want the user to be able to check the box next to one of them and hit submit. After the submit button is clicked it will update the database the value of "yes" in the completed field. Below is my code:
<?php
//Create registration form (register.php)
include "db_connect.php";
if(!isset($_POST['submit']))
{
echo "
<fieldset><legend><h2>Trouble Ticket List</h2></legend><br>
<form action=\"#\" method=\"post\" >
<table width=\"980\" class=\"ticket-table\">
<tr>
<th><strong>Name:</strong></th>
<th><strong>Phone:</strong></th>
<th><strong>Domain:</strong></th>
<th><strong>Email:</strong></th>
<th><strong>Comments:</strong></th>
<th><strong>Completed:</strong></th>
</tr>
";
$sql = "SELECT * FROM `online-form` WHERE `completed` = ''";
$query = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($query))
{
$ID= $row['ID'];
$name= $row["name"];
$phone= $row["phone"];
$email= $row["email"];
$domain= $row["domain-name"];
$comments= $row["comments"];
$completed= $row["completed"];
?>
<tr>
<td>
<br /><?php echo "$name" ?>
</td>
<td>
</label><br /><?php echo "$phone" ?>
</td>
<td>
</label><br /><?php echo "$domain" ?>
</td>
<td>
</label><br /><?php echo "$email" ?>
</td>
<td>
<br /><?php echo "$comments" ?>
</td>
<td>
<input type="checkbox" name="completed" id="completed" value="yes" />
<input type="hidden" name="<?php echo $ID ?>" value="<?php echo $ID ?>" />
</td>
</tr>
<?php
} ?>
<tr>
<td><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</table>
</form>
<?php
}else{
?>
<?php
$sql = "SELECT * FROM `online-form` WHERE `completed` = ''";
$query = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($query);
$ID= $_POST['ID'];
echo $ID;
$completed = $_POST['completed'];
$errors = array();
$sql = "UPDATE `online-form` SET completed = 'yes' WHERE ID = '$ID'";
$result=mysql_query($sql) or die(mysql_error() . '<br />' . $sql);
echo "The User has been updated.<A HREF=\"javascript:history.go(-1)\">Go Back to List</A> ";
}?>