I have a table that is populated by database and each of the rows is a from with a submit button. The idea is there is a drop down selection and upon selecting it then submitting the form updates the database. The problem is that the row form does not disappear only after pressing the submit agian and then it updates the database again, but it does disappear. Thanks

<?php
//WHERE `inspection`.`inspection_date`='".date('Y-m-d')."'
mysql_select_db($database_cdocsconnect, $cdocsconnect);
$query_rslistInspection = "SELECT `inspection`.`idinspection`,`inspection`.`inspection_date`,`inspection`.`am_pm`,`inspection`.`pass_failed`,
`inspection`.`Permit_No`AS `Permit Number`,`typeofinspection`.`DescriptionOfInspection`AS `Inspection Type`,
`permit_classification`.`classification`AS `Permit Type`,`inspection`.`comments`,CONCAT(`employe_list`.`first_name`,`employe_list`.`last_name`) AS `Inspector`
FROM `inspection` 
LEFT JOIN employe_list ON employe_list.contact_id = inspection.idemployee 
LEFT JOIN permit_classification ON permit_classification.id_permit_classification = inspection.permit_ClassID 
LEFT JOIN typeofinspection ON typeofinspection.Type_Inspection_ID = inspection.TypeInspectionID 
WHERE `inspection`.`assigned` ='1' AND inspection.inspection_date=CURDATE()";
$rslistInspection = mysql_query($query_rslistInspection, $cdocsconnect) or die(mysql_error());
$row_rslistInspection = mysql_fetch_assoc($rslistInspection);
$totalRows_rslistInspection = mysql_num_rows($rslistInspection);mysql_select_db($database_cdocsconnect, $cdocsconnect);

mysql_select_db($database_cdocsconnect, $cdocsconnect);
$query_rsinspectors = "SELECT `contact_id`, CONCAT(`first_name`, `last_name`)AS Inspector
FROM employe_list";
$rsinspector = mysql_query($query_rsinspectors, $cdocsconnect) or die(mysql_error());
$row_rsinspector = mysql_fetch_assoc($rsinspector);
$totalRows_rsinspector = mysql_num_rows($rsinspector); mysql_select_db($database_cdocsconnect,$cdocsconnect);

if(isset($_POST['id_inspection'], $_POST['inspector']))
{
  $idinspection = $_POST['id_inspection'];
  $id_inspector = $_POST['inspector'];  
  mysql_query("UPDATE inspection SET idemployee ='$id_inspector',last_modified = now(), assigned ='0'
  WHERE idinspection ='$idinspection';");
}
?>
<?php
include 'init.php';

$employee_page_authorized = 7;
$user_page = user_page();
//echo $user_page; to test what number is returned from the database
if($user_page == $employee_page_authorized)
{   
    if (logged_in())
    {
        include 'template/header.php';
        ?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
            <head>
            <link href="css/style.css" rel="stylesheet " type="text/css" />
            <style type="text/css"></style>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>Dashboard</title>
            </head>

            <body>
                <p></p>
                    <div id="wrapper">
                        <div id="leftcol">
                           <?php include('leftsidemenu.php'); ?>
                        </div>
                        <div id="content">
                            Inspections that need assigend for <?php echo date('m-d-Y');//display the date in the correct format?><br />
                            <table width="93%" border="0" align="center" cellpadding="2" cellspacing="2" id="showInspection">
                              <tr>
                                <th width="8%" align="center" valign="middle" nowrap="nowrap" scope="col">Permit No.</th>
                                <th width="11%" align="center" valign="middle" nowrap="nowrap" scope="col">Inspection No.</th>
                                <th width="7%" align="center" valign="middle" nowrap="nowrap" scope="col">Date</th>
                                <th width="8" align="center" valign="middle" nowrap="nowrap" scope="col"><p>AM / PM</p></th>
                                <th width="12%" align="center" valign="middle" nowrap="nowrap" scope="col">Inspection Type</th>
                                <th width="10%" align="center" valign="middle" nowrap="nowrap" scope="col">Permit Type</th>
                                <th width="13%" align="center" valign="middle" nowrap="nowrap" scope="col">Comments:</th>
                                <th width="15%" align="center" valign="middle" nowrap="nowrap" scope="col">Inspector:</th>
                              </tr>
                              <?php do 
                              { ?>
                                <tr align="center">
                                <form id="form1" name="form1" method="post" action="assign_inspections.php">
                                    <?php
                                    $pf=$row_rslistInspection['pass_failed']; 
                                    $permit_no= $row_rslistInspection['Permit Number']; 
                                    $id_inpsection=$row_rslistInspection['idinspection'];
                                    $inpection_date=$row_rslistInspection['inspection_date'];
                                    $a_p=$row_rslistInspection['am_pm'];
                                    $inspection_type=$row_rslistInspection['Inspection Type'];
                                    //$id_employee=$row_rslistInspection['idemployee'];
                                    $permit_type=$row_rslistInspection['Permit Type']; 
                                    $comments=$row_rslistInspection['comments'];
                                    $inspector=$row_rslistInspection['Inspector']; 
                                    ?>
                                      <td><input type="text" name="permitNo" size="11" value="<?php echo $permit_no;?>" /></td>
                                      <td><input type="text" name="id_inspection" size="11" value="<?php echo $id_inpsection;?>" /></td>
                                      <td><input type="text" name="inspectiondate" size="10" value="<?php echo $inpection_date;?>" /></td>
                                      <td width="8"><input name="a_p" type="text" value="<?php echo $a_p; ?>" size="8" /></td>
                                      <td><input type="text" name="inspectiontype" size="15" value="<?php echo $inspection_type; ?>" /></td>
                                      <td><input type="text" name="permittype" size="15" value="<?php echo $permit_type; ?>" /></td>
                                      <td><input type="text" name="comments" size="30" value="<?php echo $comments; ?>" /></td>
                                      <td>
                                      <select name="inspector" style="background-color:#FF7D7D" ><option value="0">Please select</option>
                                        <?php
                                          do 
                                          {  
                                          ?>
                                            <option value="<?php echo $row_rsinspector['contact_id']; ?>" ><?php echo $row_rsinspector['Inspector']; ?></option>
                                            <?php $id_inspector = $row_rsinspector['contact_id'];
                                           }while ($row_rsinspector = mysql_fetch_assoc($rsinspector));
                                             $rows = mysql_num_rows($rsinspector);
                                             if($rows > 0) 
                                             {
                                               mysql_data_seek($rsinspector, 0);
                                               $row_rsinspector = mysql_fetch_assoc($rsinspector);
                                             }
                                             ?>
                                      </select></td>
                                      <td width="6%"><input type="submit" value="Submit"  /></td>
                                </form>
                                </tr>
                                <?php 
                              }  while ($row_rslistInspection = mysql_fetch_assoc($rslistInspection)); 
                                 $rows = mysql_num_rows($rslistInspection);
                                             if($rows > 0) 
                                             {
                                               mysql_data_seek($rslistInspection, 0);
                                               $row_rslistInspection = mysql_fetch_assoc($rslistInspection);
                                             }
                                ?>

                              </table>
                        </div><!--content -->
                    </div><!--wrapper -->
                <p>&nbsp;</p>
            </body>
        </html>
        <?php
        mysql_free_result($rslistInspection);

      ?>
      <?php
          include 'template/footer.php';
  } //if logged in all the above is done

}//authorized user page specific
else
    {
    echo"  Aera Restricted!";
    exit();
    //header('Location: ../login_page.php');    
    }

?>
Member Avatar for LastMitch

@tokick4

I have a table that is populated by database and each of the rows is a from with a submit button. The idea is there is a drop down selection and upon selecting it then submitting the form updates the database.

I think you post your code in the wrong section. This question is suited for PHP section. Why did you post this question here?

The problem is that the row form does not disappear only after pressing the submit agian and then it updates the database again, but it does disappear. Thanks

What error did you get when you submitted the code? It should say an error.

I'm curious why there's no INSERT statement but you have UPDATE statement?

I do it this way: first SELECT then INSERT (new values) then UPDATE (new values) then SELECT (new values).

You have an <option value> tag does it fetch anything from the ID?

I dont get an error, the code works it updates the database when the option value is selected and the submit is clicked and the page reloads the table, it just will not disappear from the table until the page reloads for the second time. This is just to assign a person in the database. I had it working several months ago but then something happend to the file and I had to reconstruct and I am leaving something out. I am thinking that I am leaving out some JavaScript to do it but I just cannot remember. Thanks for the reply LastMitch.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.