0

I want to insert selected rows in the database but I am unable to get count of checked check-boxes. However in one of my form where I am updating records I could get count but here I couldn't. Code is as below

<tr class="odd gradeX">
    <td>
        <input type="checkbox" class="checkboxes" value="<?php echo $row['student_id']; ?>" name="ids[]" />
    </td>
    <td>
        <?php echo $row['first_name']." ".$row['last_name'];?>
    </td>
    <td>
        <?php echo $row['father_mobile'];?>
    </td>
    <td class="hidden-480">
        <a href="mailto:<?php echo $row['email'];?>">
            <?php echo $row['email'];?>
        </a>
    </td>
    <td class="hidden-480">
        <?php echo $row['address'];?>
    </td>
    <td class="center hidden-480">
        <?php echo $row1['track_name'];?>
    </td>
    <td>
        <?php echo $row2['level_name'];?>
        </span>
    </td>
</tr>



<?php     

if(isset($_POST['move']))
{
    echo "count is" . count($_POST["ids"]);
    for($i=0; $i<count($_POST["ids"]); $i++){
        echo $sql = "inset into tbl_student_batches set  bacth_id='".$_POST['batch_id']."',student_id='".$_POST['ids']."'";
        if (mysql_query($sql)) {
            $msg = "Selected students moved to next batch successfully";
            header("location:convert_level?msg=$msg");
        }else{
            $errmsg = ("Error while moving.". mysql_error()); 
        }
    }  
}
Wilt
  • 41,477
  • 12
  • 152
  • 203
  • Are you actually getting `ids` on server in post request? Is your `move` set so that your condition is true? Add `print_r($_POST);` in front of your `if(isset($_POST['move']))` and check what are you getting in request and if `ids` is there and what does it contain. Also, your code is vulnerable to SQL injections. – pisamce Jun 29 '15 at 05:29
  • where do you set `POST['move']` ? You're not appearing to show all the relevant code, you don't appear to have a `
    ` object, you are using a deprecated MySQL and really should get into the habit of using MySQLi or PDO (please see http://stackoverflow.com/questions/31103984/an-injection-attack-that-succeeds-with-mysql-query-but-fails-with-mysqli-query/31104196#31104196 )
    – Martin Jun 29 '15 at 05:31
  • no i am not getting ids. actually ids are printing in for loop in table as shown in code. – Atul Suroshe Jun 29 '15 at 05:33
  • Can you post your entire form, is it dynamically generated? Or is there a fixed number of checkboxes? Did you set a methode? a lot of questions about your form. – PHPeter Jun 29 '15 at 06:48
  • its dynamically generated checkboxes – Atul Suroshe Jun 29 '15 at 08:59

1 Answers1

0

you can try in this way

      $studentIds = explode(' ', $_POST['ids']);
      $totalId= count($studentIds);
Dipesh More
  • 109
  • 1
  • 14