selected checkbox value not deleted

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • palanidharma
    New Member
    • Feb 2008
    • 10

    selected checkbox value not deleted

    hi,
    i writing the code for selectd check box value deleted.but the code not working


    <?php
    include("conn.p hp");
    $sel= mysql_select_db ("sangoma");
    //include("functi on.php");

    ?>
    <form method='post' action='test3.p hp' name='agentdisp '>
    <?php
    $sql = "Select * from test;";
    $result=mysql_q uery($sql) or die ("<br> Could not Retrieve Data <br>");
    $num_rows=mysql _num_rows($resu lt);
    While ($row =mysql_fetch_ar ray($result))
    {
    $currentCom_id = $row['com_id'];
    echo $currentCom_id;
    ?>
    <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['com_id']; ?>">
    <?php
    }
    ?>
    <input name="delete" type="submit" id="delete" value="Delete">





    <?
    // Check if delete button active, start this
    if($_POST['delete'] == 'Delete')
    {
    for($i=0;$i<$co unt;$i++)
    {
    $del_id = $_POST['checkbox'][$i];
    $sql = "DELETE FROM test WHERE com_id='$del_id '";
    $result = mysql_query($sq l);
    }

    }

    mysql_close();

    ?>
    </form>


    pls reply me...
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Originally posted by palanidharma
    hi,
    i writing the code for selectd check box value deleted.but the code not working


    <?php
    include("conn.p hp");
    $sel= mysql_select_db ("sangoma");
    //include("functi on.php");

    ?>
    <form method='post' action='test3.p hp' name='agentdisp '>
    <?php
    $sql = "Select * from test;";
    $result=mysql_q uery($sql) or die ("<br> Could not Retrieve Data <br>");
    $num_rows=mysql _num_rows($resu lt);
    While ($row =mysql_fetch_ar ray($result))
    {
    $currentCom_id = $row['com_id'];
    echo $currentCom_id;
    ?>
    <input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['com_id']; ?>">
    <?php
    }
    ?>
    <input name="delete" type="submit" id="delete" value="Delete">





    <?
    // Check if delete button active, start this
    if($_POST['delete'] == 'Delete')
    {
    for($i=0;$i<$co unt;$i++)
    {
    $del_id = $_POST['checkbox'][$i];
    $sql = "DELETE FROM test WHERE com_id='$del_id '";
    $result = mysql_query($sq l);
    }

    }

    mysql_close();

    ?>
    </form>


    pls reply me...
    what is $count?
    [PHP]for($i=0; $i<count($_POST['checkbox']); $i++)
    {
    if (isset($_POST['checkbox'][$i])) $del_id = $_POST['checkbox'][$i];
    $result = mysql_query("DE LETE FROM `test` WHERE `com_id`='".$de l_id."'");
    }
    [/PHP]

    And please format your message well before posting.

    Comment

    • ronverdonk
      Recognized Expert Specialist
      • Jul 2006
      • 4259

      #3
      This is the fourth time (3 via forum, 1 via PM) that you are requested to follow some simple Posting Guidelines and enclose any code within the appropriate code tags!

      If you have no intention or do not wish to follow some simple forum rules, I will block your next post!!

      moderator

      Comment

      Working...