By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,414 Members | 1,024 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,414 IT Pros & Developers. It's quick & easy.

selected checkbox value not deleted

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


<?php
include("conn.php");
$sel= mysql_select_db("sangoma");
//include("function.php");

?>
<form method='post' action='test3.php' name='agentdisp'>
<?php
$sql = "Select * from test;";
$result=mysql_query($sql) or die ("<br> Could not Retrieve Data <br>");
$num_rows=mysql_num_rows($result);
While ($row =mysql_fetch_array($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<$count;$i++)
{
$del_id = $_POST['checkbox'][$i];
$sql = "DELETE FROM test WHERE com_id='$del_id'";
$result = mysql_query($sql);
}

}

mysql_close();

?>
</form>


pls reply me...
Feb 16 '08 #1
Share this Question
Share on Google+
2 Replies


hsriat
Expert 100+
P: 1,654
hi,
i writing the code for selectd check box value deleted.but the code not working


<?php
include("conn.php");
$sel= mysql_select_db("sangoma");
//include("function.php");

?>
<form method='post' action='test3.php' name='agentdisp'>
<?php
$sql = "Select * from test;";
$result=mysql_query($sql) or die ("<br> Could not Retrieve Data <br>");
$num_rows=mysql_num_rows($result);
While ($row =mysql_fetch_array($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<$count;$i++)
{
$del_id = $_POST['checkbox'][$i];
$sql = "DELETE FROM test WHERE com_id='$del_id'";
$result = mysql_query($sql);
}

}

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("DELETE FROM `test` WHERE `com_id`='".$del_id."'");
}
[/PHP]

And please format your message well before posting.
Feb 16 '08 #2

ronverdonk
Expert 2.5K+
P: 4,258
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
Feb 16 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.