0

i am trying to delete some rows but i dont know where i am mistaking please check this below code and suggest my error with solution:

if(isset($_GET['delete']) && $_GET['delete']=="true")
{
     $checkbox = $_POST['checkbox'];
     for($i=0;$i<count($checkbox);$i++)
     {
         echo $checkbox[$i]; // here i am going to write delete query
     }
}

Now my HTML code for that. I have created a table for users.

it looks something like this in HTML

<table id="sample_2">
    <thead>
       <tr>
           <th style="width:8px;"><input type="checkbox" class="group-checkable" data-set="#sample_2 .checkboxes" /></th>
                                                                       <th>Username</th>
            <th>Full Name</th>
            <th class="hidden-480">Email</th>
            <th>Mobile</th>    
            <th>Activation Key</th>
            <th class="hidden-480">Status</th>
       </tr>
    </thead>
     <tbody>
           <?php $user_details->all_user_details(); ?>

     </tbody>
</table>

Now here is the function i am using. to create table rows. So check this out:

while ($row = $database->fetch_array($result_set)) {
                    $single_row ="<tr class=\"odd gradeX\">
                                            <td><input type=\"checkbox\" name=\"checkbox[]\" class=\"checkboxes\" value=\"".$row["userid"]."\" /></td>
                                            <td>".$row['username']."</td>
                                        <td>".$row['fullname']."</td>
                                            <td class=\"hidden-480\"><a href=\"mailto:".$row['email']."\">".$row['email']."</a></td>
                                        <td>".$row['mobile']."</td>
                                        <td>".$row['user_activation_key']."</td>";
                                        if($row['status']==1){ 
                                            $single_row .= "<td><span class=\"label label-success\">Approved</span></td>";
                                         } else{ 
                                            $single_row .= "<td><span class=\"label label-danger\">Pending</span></td>"; }
                    $single_row .="</tr>";



                echo $single_row;                   

    }

any solution for this problem? I know i am making mistake somewhere in $_POST['checkbox'] while getting the value, Please suggest.

Thank you!

user3201500
  • 1,538
  • 3
  • 22
  • 43

1 Answers1

0

this is your first problem:

if(isset($_GET['delete']) && $_GET['delete']=="true")
{
     $checkbox = $_POST['checkbox'];
     for($i=0;$i<count($checkbox);$i++)
     {
         echo $checkbox[$i]; // here i am going to write delete query
     }
}

please change it to this:

if (isset($_GET['delete']))
{
  if ($_GET['delete']=="true") {
     $checkbox = $_POST['checkbox'];
     for($i=0;$i<count($checkbox);$i++)
     {
         echo $checkbox[$i]; // here i am going to write delete query
     }
  }
}

and also you forgot to leave a space between if and (

Mahdi Jazini
  • 791
  • 9
  • 16