I am using PHP to change the value of a dropdownlist menu in my database. The status I am using are: New - progress - Wait - Done - Close Suppose that all the new entry are with status "NEW"
When I change the value I can still see a double option.
Here my code:
<td>
<select class='form-control col-sm-10' id='status' name='status'>
<option value=" . $row['status'] . " >" . $row['status'] . "</option>
<option value='new'>New</option>
<option value='progress'>Progress</option>
<option value='wait'>Wait</option>
<option value='done'>Done</option>
<option value='close'>Close</option>
</select>
</td>
--------------------- FULL CODE --------------
<?php
include("../includes/connection.php");
if ($link->connect_errno > 0) {
die('Unable to connect to database [' . $link->connect_error . ']');
}
if (isset($_POST['update'])) {
$results = $link->query("UPDATE job SET status='$_POST[status]', priority='$_POST[priority]' WHERE id='$_POST[hidden]'");
$results = $link->query("UPDATE customer SET status='$_POST[status]' WHERE id='$_POST[hidden]'");
}
$sql = "SELECT * from job";
if (!$result = $link->query($sql)) {
die('There was an error running the query [' . $link->error . ']');
}
echo "
<table class='table'>
<thead>
<tr>";
/* Get field information for all columns */
while ($finfo = $result->fetch_field()) {
echo "
<th>" . $finfo->name . "</th>";
}
echo "
</tr>
</thead>
<tbody>";
while ($row = $result->fetch_assoc()) {
$job_id = $row['id'];
echo "<form action='' method=post>";
echo "<tr class='info'>
<input type=hidden name=hidden value=" . $row['id'] . ">
<td>" . $row['id'] . "</td>
<td>" . $row['device'] . "</td>
<td>" . $row['model'] . "</td>
<td>" . $row['problem'] . "</td>
<td><select class='form-control col-sm-10' id='status' name='status'>
<option value=" . $row['status'] . " >" . $row['status'] . "</option>
<option value='new' >New</option>
<option value='progress'>Progress</option>
<option value='wait'>Wait</option>
<option value='done'>Done</option>
<option value='close'>Close</option>
</select></td>
<td><select class='form-control col-sm-10' id='priority' name='priority'>
<option value=" . $row['priority'] . " >" . $row['priority'] . "</option>
<option value='high'>High</option>
<option value='medium'>Medium</option>
<option value='low'>Low</option>
</select></td>
<td> <button type='submit' class='btn btn-primary btn-sm' name='update'>Update</button></td>
<td> <a class='btn btn-primary btn-sm' data-toggle='modal' data-target='#myModal' name='[$job_id]' value='[$job_id]' > Info</a></td>
</tr>";
echo "</form>";
}
echo "
</tbody>
</table>";
?>

$row['status']contains the selected option