phpHow do I create an html form with multiple checkboxes

This is my code for creating an html form that reads from a database and will allow the user to check and uncheck boxes for each of the 640 items. This is the form.php:

// execute query
$result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());

// see if any rows were returned
if (mysql_num_rows($result) > 0) {
    // yes
    // print them one after another
    echo "<html><body>  <table cellpadding=10 border=1>";
    while($row = mysql_fetch_assoc($result)) {
        echo "<tr>";
        echo "<td>".$row['stickerID']."</td>";
        echo "<td>" .$row['stickerName']."</td>";
        echo "<td>".$row['stickerSection']."</td>";
        echo "<td>"?>
                 <form name="some form" action="editform.php" method="post">
                 <input type="checkbox" name="<?php echo $row['stickerID'] ?>" value=" <?php echo $row['stickerStatus'] ?> ">
                 <?php "</td>";
        echo "</tr>";
    echo "</table></body></html>";
    echo " " ?>
                 <input type="submit" name="editWish" value="Edit">
                 <?php " ";
} else {
    // no
    // print status message
    echo "No rows found!";

The user must then be able to click on submit and have those values updated in the mysql database.

Right now when I click the submit button, it posts to edit form.php which has this:


//echo results
foreach($_POST['stickerID'] as $k=>$v ){
echo $k;
echo $v;


But I don't get anything echoed. I was thinking the problem could be that Im actually creating a form for every row instead of 1 form with many rows/checkboxes. But when I move the form code after the and the tag to the line where line, I can't even load the form.php, it just loads blank.

Where is my problem? :) Thx

Name your checkbox like this:

<input type="checkbox" name="stickerID[]" value=" <?php echo $row['stickerStatus']; ?> ">

And as Amal already said update your code to PDO or MySQLi

you can do this with a tag :-

echo "<td>" .$row['stickerName']."</td>";
        echo "<td>".$row['stickerSection']."</td>";
        echo "<td>"?>

                 <form name="some form" action="editform.php" method="post">
                 <input type="checkbox" name="checkbox[]" value=" <?php echo $row['stickerStatus'] ?> ">
                 <?php "</td>";
        echo "</tr>";

on your php code you get :-

$all_checkes_checkbox = $_POST['checkbox'];

here is your all checked checkbox:-
and this array also bale key and value

Related Articles
  • Let's imagine a HTML-form with with two submit buttons. one of them is positioned in the upper half of the form and does something less important. the other button is the actual submit button, which saves the entered data. this button is positioned a
  • I have an HTML form - with PHP, I am sending the data of the form into a MySQL database. Some of the answers to the questions on the form have checkboxes. Obviously, the user does not have to tick all checkboxes for one question. I also want to make
  • I am trying to create a program in which a user can update any specific product. When a user click on UPDATE button, a form opens. I want to populate HTML form with MySQL data. I have written the following code but its giving me an error message. I a
  • I am going to create an application for displaying the installed applications (and their icons) in a listview which will contain multiple checkboxes. How can I do this? If it's possible, please tell me the way. I knew about this example for listview
  • I'm trying to create a html tabbed form where each named tab has a common set of inputs defined in a common div. When submit is hit, I'd like all the inputs from all the tabs are returned. Not a problem if unchecked checkboxes are missed. Each input
  • I'm new to Yii framework.I'm using the form.php to update the fields of the table. So now I use this form with three submit buttons - [Save, Accept, Reject]. The form now has the following fields. <div class="row"> <?php //$model->Re
  • I am trying to implement a 'reset password' page for my website. So far I have a simple page with a form for the user to enter their email address. Submitting the form calls 'requestpasswordreset.php' which does things such as checking if there exist
  • I'm using jQuery and PHP to post a long dynamically created HTML Form. Since I need to have a "Sending" dialog and show the results on the same page (ideally in a jQuery popup), I do not use the traditional HTML form submit. What I'm doing works
  • I have a very large form that's essentially a questionnaire. It has 19 questions, some of which when answered Yes have 1-5 more questions dropdown. The way I'm doing this now is using jQuery .change() and .hide()/.show(). If the answer to a question
You Might Also Like