0

In checkbox when I selected it then value(1) is going to database but when I am not selected Zero(0) is not going to DB and error is like A

Database Error Occurred

Error Number: 1048 Column 'paid' cannot be null

INSERT INTO topic (title, description, content, attachment, courseId, sectionId, type, paid) VALUES ('Mysql Unit 1', 'Mysql unit description', 'video1.mp4', 'upload.mp4', '292', '83', 'unit', NULL)

Filename: C:/xampp/htdocs/ci3/system/database/DB_driver.php

Line Number: 691

addunit.php

 <td>
    <div class="form-item form-checkbox checkbox-style">
    <input type="checkbox" id="make" name="free" value="1">
       <label for="make">
          <i class="icon-checkbox icon md-check-1"></i>
          Make this Unit as Free
       </label>
    </div>
 </td>

checkbox

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Kevin
  • 653
  • 2
  • 13
  • 34
  • when unchecked nothing related to checkbox gets submitted, one alternative is to use hidden inputs – Nodir Rashidov Mar 17 '17 at 06:19
  • as in, set a hidden in the form, if checkbox is checked, ignore hidden, otherwise refer to the hidden input value – Nodir Rashidov Mar 17 '17 at 06:20
  • Possible duplicate of [Post the checkboxes that are unchecked](http://stackoverflow.com/questions/1809494/post-the-checkboxes-that-are-unchecked) – caramba Mar 17 '17 at 06:23

1 Answers1

1

Checkbox doesn't return any value if it is unchecked? So, if you want such to check whether it was checked or not you better use the isset method of PHP. For example:

$isFree = isset($_POST['free']

Then use this $isFree variable to insert into DB.

Imran
  • 4,582
  • 2
  • 18
  • 37