Dynamic checkbox with PHP and MySQL

Wednesday 12 June 2019

Sample HTML/PHP Form:

<?php
include("config.php");
?>
<!DOCTYPE html>
<html>
<body>

<form method="post" action="" enctype="multipart/form-data">
<?php
$sql=mysqli_query($conn,"SELECT * FROM sales");
while($rs=mysqli_fetch_array($sql)){ ?>
  Checkbox:<br>
  <input type="checkbox" name="bike_id[]" class="names" value="<?php echo ['field_name']; ?>">
  <br>
  <?php } ?>
  <input type="submit"  name="Submit">
</form>
</body>
</html>

PHP Code:

<?php
if(isset($_POST['bike_id'])){
        $invite = $_POST['bike_id'];
        print_r($invite);
    }
?>

Output:

Array ( [0] => 1 [1] => 2 )

4 comments

  1. I want Help For the Problem I am facing: https://stackoverflow.com/questions/56951285/dynamic-table-having-multiple-checkbox-missing-first-rows-checked-checkbox-val

    Multiple checkbox of same name in multiple row doesn't submit checked one as value and unchecked one as Zero

    ReplyDelete
    Replies
    1. zensparkenterprises@gmail.com

      Delete
    2. Just write one sub query like, whatever values is checked update as 1 and not in as 0.

      Delete
  2. https://manikandancbe.blogspot.com/2019/07/dynamic-checkbox-with-php-and-mysql-on.html

    Check this one, let me know its helpful for you or not.

    ReplyDelete

 

Blogger news

Blogroll

Most Reading