0

I'm working on last part on my project, I'm building web-site, in this part, I want to display options of a job ( whether the job still in progress or Completed ) I gave my row in mysql enum values, "Completed","InProgress" and when the student pick a job, the JobStatus will be "InProgress" and the student can change this value from his JobLists page, when it's done, he can change it to Completed. and it will be changed in the Database and this is my code trying to, in this Code, it shows me an Error on the Update Query JobStatus = '".$_POST['JobStatus'] is not Defined ?? any one can help PLEASE Guys

<?php 
  //Connect to DB
include('CIEcon.php');

$sqlCommand ="SELECT Accounts.SSU , Jobs.JobName, Jobs.Description, Jobs.DueDate,Jobs.JobId, JobsLists.JobStatus FROM JobsLists,Jobs,Accounts WHERE  Accounts.SSU = JobsLists.SSU AND Jobs.JobId = JobsLists.JobId  And Accounts.SSU = '".$_SESSION['SSU']."'  ";

$result = mysqli_query($dbCIE,$sqlCommand) or die(mysql_error()); 

 echo "<form  action='JobsLists.php' method='post'>";


while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td> <input type='checkbox'  name='JobId[]'  value='". $row['JobId'] ."'  /> </td>";
echo "<td align=center>" . $row['SSU'] . "</td>";
echo "<td align=center>" . $row['JobName'] . "</td>";
echo "<td align=center> " . $row['Description'] . "</td>";
echo "<td align=center>" . $row['DueDate'] . "</td>";
echo "<td align=center>" . 
"<select>
  <option name = JobStatus[".$row['JobId']."] value='InProgress' selected> In Progress </option>
  <option name = JobStatus[".$row['JobId']."] value='Completed'          >     Completed </option>
</select>" . "</td>"; // need to be worked on.. 
echo "</tr>";
}
"</table>";

//Connect to DB
include('CIEcon.php');

// save the SSU for the current user to save the sata when insert jobs in jobslist
$SSU = $_SESSION['SSU']; 
/////


//handle this when to save a status. 
if( isset($_POST['save']) ){
    if( empty($_POST['JobId']) || $_POST['JobId'] == 0 ){
      echo"<h4>  Status Wasn't Changed..  </h4>";
              }else{ 
include('CIEcon.php');  //$dbCIE 
foreach($_POST['JobId'] AS $i){
    /// update JobsLists table with the new status..  
     $sqlUpdate = "UPDATE  JobsLists SET JobStatus = '".$_POST['JobStatus'][$i]."'  WHERE JobId = '" . $i . "'";
     $resultUpdate = mysqli_query($dbCIE,$sqlUpdate) or die(mysqli_error($dbCIE));

}

// TEST ONLY ////////----------------------------------------////////////
if (mysqli_affected_rows($dbCIE) > 0) {
  echo "<h4> You have successfully Saved your statuse </h4>";

}else{ echo "<h4> Error occurred </h4> "; }
////////----------------------------------------////////////


                }  // end of else, when user select something.. 
            } 


?>

1 Answer 1

1

It's because you haven't named the select box which you are trying to send values with.. HTML <option>s don't have a name, but only a value. it is this value which is the assigned to the name of the <select> in $_POST

 while($row = mysqli_fetch_array($result))
    {
    echo "<tr>";
    echo "<td> <input type='checkbox'  name='JobId[]'  value='". $row['JobId'] ."'  /> </td>";
    echo "<td align=center>" . $row['SSU'] . "</td>";
    echo "<td align=center>" . $row['JobName'] . "</td>";
    echo "<td align=center> " . $row['Description'] . "</td>";
    echo "<td align=center>" . $row['DueDate'] . "</td>";
    echo "<td align=center>" . 
    echo "<select name='JobStatus[".$row['JobId']."]'>";
        if($row['JobStatus'] == "InProgress"){
           echo  "<option value='InProgress' selected>In Progress</option>";  
           echo "<option value='Completed'>Completed</option>";
        } else {
            echo  "<option value='InProgress'>In Progress</option>";  
           echo "<option value='Completed' selected> Completed </option>";

        } 

    echo "</select>" . "</td>"; // need to be worked on.. 
    echo "</tr>";
    }
    "</table>";
Sign up to request clarification or add additional context in comments.

2 Comments

how do you mean the default value?
thank u sir, but when I select "complete" and refresh the page, I Want to option to stay "Complete" .. do u know how do I do that ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.