Marco M
Marco M

Reputation: 59

PHP - Check box does not implode and getting updated in the database

Well what my goal is to get the values of the selected checkboxes and then implode the array so that it is in a string format and then I could already insert in the database.

echo "  
<div class='modal fade' id='modalRejectCEO' role='dialog'>
    <div class='modal-dialog modal-lg'>
      <div class='modal-content'>
        <div class='modal-header'>
          <button type='button' class='close' data-dismiss='modal'>&times;</button>
          <h4 class='modal-title'>Reject ".$strings["project"].": ".$projectDetail->pro_name[0]."</h4>
        </div>
        <div class='modal-body'>
          <h5>Please specify the reason for rejecting the project ".$projectDetail->pro_name[0].". (eg. Reason is too vague)</h5>
          <form>
          <input type='checkbox' name='projectInfo[]' value='location'><b>Location: </b>".nl2br($projectDetail->pro_street_address[0]).", ".nl2br($projectDetail->pro_city_province[0])." <br><br>
          <input type='checkbox' name='projectInfo[]' value='date'><b>Date: </b>".$projectDetail->pro_start_date[0]." - ".$projectDetail->pro_end_date[0]." <br><br>
          <input type='checkbox' name='projectInfo[]' value='summary'><b>Project Description: </b><br><br>".nl2br($projectDetail->pro_description[0])."<br><br>
          <input type='checkbox' name='projectInfo[]' value='objectives'><b>Objectives: </b>".nl2br($projectDetail->pro_objectives[0])."<br><br>
          </form>

            <div class='input-group'>
                <span class='input-group-addon' id='basic-addon1' style='width:500px;'>Reason for Rejection:</span>
                <input type='text' id='reasonCEO' name='reasonCEO' class='form-control' style='width:500px;' placeholder='' aria-describedby='basic-addon1'>
            </div>

        </div>
        <div class='modal-footer'>
            <input type='submit' id='rejectCEO' class='btn btn-primary' name='rejectCEO'>
        </div>
      </div>
    </div>
  </div>

  ";

And this is triggers the update method of SQL

    if(isset($_POST['rejectCEO']) && $_POST['reasonCEO'] != ""){
        $selectedReason = implode(', ',$_POST['projectInfo']);

        $query3="UPDATE projects 
        SET project_status = '3', reason = '".$_POST['reasonCEO']."', reason_referrer = '".implode(',',$_POST['projectInfo'])."'
        WHERE id =".$idProj."";      

        retrieveTable($query3);
        header('Location: listprojectsprojectproposal.php');
}

Upvotes: 1

Views: 35

Answers (1)

Funk Forty Niner
Funk Forty Niner

Reputation: 74217

I'm posting this as a community wiki. I don't want rep for it, nor should any be made from it.


As I said, you closed off your </form> too early.

Error reporting would have helped here also.

Btw, your code's open to an SQL injection. Use a prepared statement:

Upvotes: 2

Related Questions