I'm building data entry and update pages using PHP/MySQL. I have a checkbox field that evaluates to an ENUM('yes','no') data type in MySQL. In the update data page I've got the following code in the page that shows the data:

<input type="checkbox" name="ready_for_enrollment" id="ready_for_enrollment" value="yes" <? if ($ready_for_enrollment) { echo ' checked '; } ?>>

The checkbox value is updating all right, but I'm still getting the following error when I click to submit the form to update the record:

Notice: Undefined index: ready_for_enrollment in D:\Inetpub\dist-web\users\sagea\php_mysql\do_modcourse.php on line 65
Course Management System
Modify a Course - Course Updated

Line 65 is this code (from the actual page that performs the update statement. The following code is in the UPDATE statement:

ready_for_enrollment = '$_POST[ready_for_enrollment]'

Clearly there is a problem in my code here that I am not seeing. Any takers?

S./

    change this:

    ready_for_enrollment = '$_POST[ready_for_enrollment]'

    to this:

    $ready_for_enrollment = $_POST['ready_for_enrollment']

      I tried it and I got this error:

      Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in D:\Inetpub\dist-web\users\sagea\php_mysql\do_modcourse.php on line 64

      If it helps, here's the expanded update statement:

      $sql = "UPDATE $table_name SET
      	course_name = '$_POST[course_name]',
      	course_number = '$_POST[course_number]',
      	department = '$_POST[department_id]',
      	status = '$_POST[status_id]',
      	media = '$_POST[media_id]',
      	crn = '$_POST[crn]',
      	location = '$_POST[location_id]',
      	credits = '$_POST[credits]',
      	enrollment = '$_POST[enrollment]',
      	target_date = '$_POST[target_date]',
      	year_rev_or_dev_due = '$_POST[year_rev_or_dev_due]',
      	date_coursedeveloper_approval_to_dept = '$_POST[date_coursedeveloper_approval_to_dept]',
      	date_coursedeveloper_approval_rec_at_cde = '$_POST[date_coursedeveloper_approval_rec_at_cde]',
      	date_contract_req = '$_POST[date_contract_req]',
      	date_contract_to_developer = '$_POST[date_contract_to_developer]',
      	date_contract_rec_at_cde = '$_POST[date_contract_rec_at_cde]',
      	date_draft_rec_at_cde = '$_POST[date_draft_rec_at_cde]',
      	date_draft_to_idt = '$_POST[date_draft_to_idt]',
      	date_final_draft_from_idt = '$_POST[date_final_draft_from_idt]',
      	date_final_draft_to_developer = '$_POST[date_final_draft_to_developer]',
      	date_final_draft_rev_rec_from_developer = '$_POST[date_final_draft_rev_rec_from_developer]',
      	date_final_draft_rev_to_idt = '$_POST[date_final_draft_rev_to_idt]',
      	date_final_draft_rec_from_idt = '$_POST[date_final_draft_rec_from_idt]',
      	date_syllabusbb_site_to_dept_for_approval = '$_POST[date_syllabusbb_site_to_dept_for_approval]',
      	date_syllabusbb_site_approval_rec_at_cde = '$_POST[date_syllabusbb_site_approval_rec_at_cde]',
      	date_payment_req = '$_POST[date_payment_req]',
      	date_payment_issued = '$_POST[date_payment_issued]',
      	date_grader_approval_req_to_dept = '$_POST[date_grader_approval_req_to_dept]',
      	date_grader_approval_rec_at_cde = '$_POST[date_grader_approval_rec_at_cde]',
      	date_grader_contract_req = '$_POST[date_grader_contract_req]',
      	date_contract_to_grader = '$_POST[date_contract_to_grader]',
      	date_grader_contract_rec_at_cde = '$_POST[date_grader_contract_rec_at_cde]',
      	general_notes = '$_POST[general_notes]',
      	ubd1 = '$_POST[ubd1]',
      	ub1_notes = '$_POST[ub1_notes]',
      	ubd2 = '$_POST[ubd2]',
      	ubd2_notes = '$_POST[ubd2_notes]',
      	ubd3 = '$_POST[ubd3]',
      	ubd3_notes = '$_POST[ubd3_notes]',
      	ready_for_enrollment = '$_POST[ready_for_enrollment]'
      	WHERE date_id = '$_POST[date_id]'";
      
      	$result = @mysql_query($sql,$connection) or die(mysql_error());

      Thanks again,
      S./

        I'm still unable to have a checked box show in the data update form when that value is actually checked in the db or vice versa.

        Here's the code I am currently trying to use in the checkbox form element to check the box based on the enum value being 'yes' rather than 'no':

        <? if ('$ready_for_enrollment'=='yes') { echo ' checked '; } ?>

        This actually seems to work most of the time but gives me an error when the box ISN'T checked. Why is this?

        S./

          I take that back - the code I just posted doesn't seem to work at all.

          : <

          S./

            Hey all - I got it working finally. I used a simple if statement in the insert data script:

            if ('$POST[ready_for_enrollment]' != 1) {
            $
            POST['ready_for_enrollment'] = 0;
            }

            I also changed the mysql data type for this field to an int instead of an enum value; that helped.

            S./

              Write a Reply...