Page 1 of 1

3 part form help.

Posted: Fri Feb 29, 2008 5:39 am
by boosch
Hello all, I am new to the forum and to PHP so I hope I have displayed my code correctly. (NO, USE THE CODE TAG)

I am having trouble with a 3 part form in PHP. the first part of the form takes a job number and searches a table for incomplete fields and stores them in an array. The second uses a while loop to display the fields and create an input boxs for each, this is for ther user to input the data that is missing. The third part is the problematic one. I need to update the database with the values that have been put into the input boxes ibnto the database. The amount of fields can vary and I cannot figure out how to perform the last part, ive had a little go :\

Below is my code, hope you can help.

Code: Select all

<?php
//database connect
$strConn = dbConnect();
 
if(isset($_REQUEST['updateJob']))
  {
  echo "This test has worked!";
  
  //Code needed here to update the job_step table.
  
  debug($qidIncompleteFields);
  
  $strSQLUpdateFields = "UPDATE job_tracker_data.job_step
   
                            SET inputvalue = '', 
                                completed = 'Y' 
                                
                          WHERE job_id = '".$_POST['jobNo']."' 
                            AND step_id = '".$_POST[$rsTest]."'";
    
}
 
if(isset($_REQUEST['jobNo']) && !isset($_REQUEST['updateJob']))
  {
    
        // This retrieves the fields that need completing
        //Still need to update or add a new query to get current phase  
        $strSQL = "SELECT stepdesc,
                          step_id 
                     
                     FROM job_tracker_data.job j, 
                          job_tracker_data.job_step js, 
                          job_tracker_data.step s
                    
                    WHERE js.job_id = ".$_POST['jobNo']." 
                      AND js.step_id = s.ID 
                      AND js.completed = 'N'
                      AND j.ID = js.job_id
                      AND s.ID = js.step_id";
        
        // Assigns the results of the querys to the query id variable Incompltete fields.   
        $qidIncompleteFields = mysql_query($strSQL);
        
        // Starts the input form for the fields that need updating.
        echo "<form action='".$_SERVER['PHP_SELF']."?id=".$_REQUEST['id']."&t=".$_REQUEST['t']."' method='post'>";
        echo "<input type='hidden' name='t' value='".$_REQUEST['t']."'></input><input type='hidden' name='id' value='".$_REQUEST['id']."'></input>";
        echo "<input type='hidden' name='jobNo' value='".$_POST['jobNo']."'></input>";
        echo "<table align='center' cellspacing='5' cellpadding='0' class='bodyText'>";
        
        //Displays the number of rows
        //echo "number of rows = ".mysql_num_rows($qidIncompleteFields)."<br />";
        
        // A loop that outputs the data ontop the opage everytime a field is pulled from the DB.
        while ($rsIncompleteField = mysql_fetch_array($qidIncompleteFields)) 
         {
                
           echo "<tr>";
           echo "<td>".$rsIncompleteField['stepdesc']." : </td>";   
           echo "<td><input type='text' name='".$rsIncompleteField['step_id']."' id='".$rsIncompleteField['step_id']."'</td>";
           echo "</tr>";
           
        }
        
        echo "<tr><td colspan='2'><div align='right'><input name='updateJob' type='submit' value='Update Job' class='bodyText'></input></div></td></tr>";
        echo "</table>";
        echo "</form>";
       
  }  
  
if(!isset($_REQUEST['jobNo']) && !isset($_REQUEST['updateJob']))
  {
 
echo "<p class='bodyText' align='left'>Please enter the number of the job you would like to update/edit.</p>";
    
?>
 
<form action='<?=$_SERVER['PHP_SELF']."?id=".$_REQUEST['id']."&t=".$_REQUEST['t']?>' method='post'>
 <table align='center' cellspacing='5' cellpadding='0' class='bodyText'>
 <tr>
   <td>Job Number :</td>
   <td><input type="text" name="jobNo" id="jobNo"></input>
   <input type="hidden" name="t" value="<?=$_REQUEST['t']?>"></input>
   <input type="hidden" name="id" value="<?=$_REQUEST['id']?>"></input>
   </td>
   <td>
    <div align='center'>
     <input name='editJob' type='submit' value='Edit Job' class='bodyText'></input>
    </div>
   </td>
  </tr>
 </table>
</form>
 
<?
  }
?>