<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['Inq_id']; ?>"></td>
<td colspan="5" align="left" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td></tr>
<?php
foreach( $_GET['checkbox'] as $del_id ){
$sql = "DELETE FROM Inq_cat WHERE Inq_id='$del_id'";
$result = mysql_query($sql);
}
?>
vibhaJ 126 Master Poster
Use array in field name.
When form is submitted using foreach delete each element.
<?php
if(isset($_POST['delete']))
{
$checkboxAll = $_POST['checkbox'];
foreach( $checkboxAll as $key=>$del_id )
{
$sql = "DELETE FROM Inq_cat WHERE Inq_id='$del_id'";
$result = mysql_query($sql);
}
header("location:index.php");
exit;
}
?>
<form name="frm" id="frm" method="post">
<input name="checkbox[]" type="checkbox" value="1" /> Cat name 1
<input name="checkbox[]" type="checkbox" value="2" /> Cat name 2
<input name="checkbox[]" type="checkbox" value="3" /> Cat name 3
<input name="delete" value="delete" type="submit" />
</form>
kiran33 0 Newbie Poster
<?php
include("Connectivity.php");
include("Main_Temp.php");
function main()
{
?>
<head>
<link rel="stylesheet" href="style.css"/>
<title>View Detail</title>
<link href="css/css.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="jquery-1.2.1.pack.js"></script>
<script type="text/javascript">
function lookup(inputString) {
if(inputString.length == 0) {
// Hide the suggestion box.
$('#suggestions').hide();
} else {
$.post("rpc8.php", {queryString: ""+inputString+""}, function(data){
if(data.length >0) {
$('#suggestions').show();
$('#autoSuggestionsList').html(data);
}
});
}
} // lookup
function fill(thisValue) {
$('#inputString').val(thisValue).focus();;
setTimeout("$('#suggestions').hide();", 200);
}
</script>
<style type="text/css">
body {
font-family: Helvetica;
font-size: 2px;
color: #000;
}
h3 {
margin: 0px;
padding: 0px;
}
.suggestionsBox {
position: relative;
left: 30px;
margin: 10px 0px 0px 0px;
width: 200px;
background-color: #212427;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border: 2px solid #000;
color: #fff;
}
.suggestionList {
margin: 0px;
padding: 0px;
}
.suggestionList li {
margin: 0px 0px 3px 0px;
padding: 3px;
cursor: pointer;
}
.suggestionList li:hover {
background-color: #659CD8;
}
</style>
</head>
<body>
<?php
//print_r($_GET);
//foreach( $_GET['checkbox'] as $del_id ){
//
// $sql = "DELETE FROM Inq_cat WHERE Inq_id='$del_id'";
// $result = mysql_query($sql);
// echo $result;
// }
if(isset($_GET['delete']))
{
$checkboxAll = $_GET['checkbox'];
foreach( $checkboxAll as $key=>$del_id )
{
$sql = "DELETE FROM Inq_cat WHERE Inq_id='$del_id'";
$result = mysql_query($sql);
echo $result;
}
header("location:Inq_cat_view.php");
exit;
}
if($_REQUEST['All'])
{
$result = mysql_query("SELECT * FROM Inq_cat where Dels='N' order bY Inq_nm asc");
$count=mysql_num_rows($result);
}
if($_REQUEST['inputString'])
{
$veh=$_REQUEST['inputString'];
$result = mysql_query("SELECT * FROM Inq_cat where Inq_nm like '$veh%' and Dels='N' order by Inq_nm asc");
$count=mysql_num_rows($result);
}
else
{
$result = mysql_query("SELECT * FROM Inq_cat where Dels='N'");
$count=mysql_num_rows($result);
if (isset($_GET['pageno']))
{
$pageno = $_GET['pageno'];
}
else
{
$pageno = 1;
}
$query_data = mysql_fetch_row($result);
$numrows=mysql_num_rows($result);
// 3. Calculate number of $lastpa
$pno=$_GET['psize'];
if($pno==0)
{
$pno=15;
}
$rows_per_page = $pno;
$lastpage = ceil($numrows/$rows_per_page);
// 4. Ensure that $pageno is within range
$pageno = (int)$pageno;
if ($lastpage == 1)
{
$pageno = 1;
}
else if ($pageno >= $lastpage)
{
$pageno = $lastpage;
}
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query = "SELECT * FROM Inq_cat where Dels='N' order by Inq_nm $limit";
$result = mysql_query($query);
$count=mysql_num_rows($result);
}
?>
<form method="get" action="Inq_cat_view.php" name="frmcover">
<table>
<tr>
<td height="1px"></td>
</tr>
</table>
<table border="1" cellpadding="0" cellspacing="0" width="95%">
<tr height="30px" >
<td colspan="10">
<table width="100%">
<tr>
<td align="left" class="txt"><font color="#AA0000">
<b>Inquiry Master View</b></font> </td>
<td align="right">
[<a href="Inq_cat.php" style="text-decoration:none"><font color="#AA0000" class="txt">Add</font></a>]
[<a href="Main.php" style="text-decoration:none" ><font color="#AA0000" class="txt">Close</font></a>]
</td>
</tr>
<tr>
<td colspan="2">
</tr>
</table>
</td>
</tr>
<tr height="3px"><td colspan="9"></td></tr>
<?php
if($count!="")
{
?>
<tr align="right"> <td colspan="10"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="4%" style="padding-left:10px;">Inquiry Type :</td>
<td width="4%"><input type="text" id="inputString" name="inputString" onKeyUp="lookup(this.value);" onblur="fill();">
<div class="suggestionsBox" id="suggestions" style="display: none;">
<img src="upArrow.png" style="position: relative; top: -12px; left: 30px;" alt="upArrow" />
<div class="suggestionList" id="autoSuggestionsList"></td>
<td width="4%"></td>
<td width="10%"> </td>
<td width="18%" align="right">
<?php if($_REQUEST['inputString']==""){ ?>Page Size
<input type="text" name="psize" size="3" style="text-align:center" maxlength="2" onKeyPress="return onlyNumbers(event)" value="<?php echo $pno;?>"/> <input type="submit" name="submit" value="Go" class="submit"/>
<?php }
else
{?>
<input type="submit" name="All" value="All" class="submit">
<?php }
?>
</td>
</tr>
</table>
</td></tr>
<tr height="3px"><td colspan="9"></td></tr>
<tr>
</tr>
<tr bgcolor="#B7A97B" height="30">
<td align="center" width="4%" class="txt1">#</td>
<td align="center" width="4%" class="txt1">Serial No</td>
<td align="left" width="45%" style="padding-left:10px;" class="txt1"> Inquiry Type</td>
<td align="left" width="40%" style="padding-left:10px;" class="txt1">Remarks</td>
<td align="center" width="11%" colspan="2" class="txt1"> Action</td>
</tr>
<?php
if($pageno==1)
{ $sr=1; }
else
{
$sr=(($pno*($pageno-1))+1);
}
function dateconvert($date,$func)
{
if ($func == 1)
{ //insert conversion
list($day, $month, $year) = split('[/.-]', $date);
$date = "$year-$month-$day";
return $date;
}
if ($func == 2)
{ //output conversion
list($year, $month, $day) = split('[-.]', $date);
$date = "$day-$month-$year";
return $date;
}
}
while($row = mysql_fetch_array($result))
{
if(($sr%2)==0)
{
?>
<tr onMouseOver="this.className = 'hlt';" onMouseOut="this.className = 'hlt1';" bgcolor="#EBEBEB" height="23" style="font-family:Tahoma; font-size:14px;">
<?php
}
else
{
?>
<tr onMouseOver="this.className = 'hlt';" onMouseOut="this.className = 'hlt1';" height="25" style="font-family:Tahoma; font-size:14px;">
<?php
}
$id=$row['Inq_id']; ?>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $row['Inq_id']; ?>"></td>
<?php
echo "<td align=center>" . $sr. "</td>";
echo "<td align=left style='padding-left:10px;'>" . $row['Inq_nm'] . "</td>";
echo "<td align=left style='padding-left:10px;'>" . $row['Inq_rem'] . "</td>";
echo "<td align=center width='50'> <a href=\" Inq_cat.php?action=Edit&srid=".$sr."&id=" .$id."\" class=edit>Edit</a></td>";
echo "<td align=center ><a href=\" Inq_cat.php?del=Delete&id=".$id. "\" class=edit>Delete</a></td>";
echo "</tr>";
$sr++;
}
?>
<tr>
<td colspan="5" align="left" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td></tr>
<?php
//
// // Check if delete button active, start this
//
// $delete = $_REQUEST['delete'];
//
// if( $delete != '' ){
//
//
//
// foreach( $checkbox as $del_id ){
//
// $sql = "DELETE FROM Inq_cat WHERE Inq_id='$del_id'";
//
// $result = mysql_query($sql);
//
//
//
// }
// }
//
// ?>
</table>
<?php echo "<table width='50%' align='center'>";
if($_REQUEST['inputString']=="")
{
if ($pageno==1 and $lastpage==1)
{
$next=$pageno+1;
echo "<tr><td align=center> <img src=images/previous_button.PNG> </td></td>";
echo "<td align=center>";
for ($i=1;$i<=$lastpage;$i++)
{
if($i==$pageno)
{
echo $i;
}
else
{
echo "<a href='Inq_cat_view.php?pageno=$i&psize=$pno' style=color:#383E47> $i</a>";
}
}
echo "</td>";
echo "<td align=center><img src=images/next_button.PNG border=0> </a> ";
}
else if ($pageno <= 1)
{
$next=$pageno+1;
echo "<tr><td align=center><img src=images/previous_button.PNG border=0> </td></td>";
echo "<td align=center>";
for ($i=1;$i<=$lastpage;$i++)
{
if($i==$pageno)
{
echo "<font size='+2'><a href='Inq_cat_view.php?pageno=$i&psize=$pno' style=color:#383E47> $i</a></font>";
}
else
{
echo "<a href='Inq_cat_view.php?pageno=$i&psize=$pno' style=color:#383E47> $i</a>";
}
}
echo "</td>";
echo "<td align=center> <a href=Inq_cat_view.php?pageno=$next&psize=$pno' style=color:#383E47><img src=images/next_button.PNG border=0> </a> ";
}
else if($pageno >= $lastpage)
{
$prevpage = $pageno-1;
echo "<td align=center> <a href='Inq_cat_view.php?pageno=$prevpage&psize=$pno' style=color:#383E47> <img src=images/previous_button.PNG border=0></a></td>";
echo "<td align=center>";
for ($i=1;$i<=$lastpage;$i++)
{
if($i==$pageno)
{
echo "<font size='+2'><a href='Inq_cat_view.php?pageno=$i&psize=$pno' style=color:#383E47> $i</a></font>";
}
else
{
echo "<a href='Inq_cat_view.php?pageno=$i&psize=$pno' style=color:#383E47> $i</a>";
}
}
echo "</td>";
echo "<td align=center><img src=images/next_button.PNG border=0> </td> ";
}
else
{
$prevpage = $pageno-1;
echo "<td align=center> <a href='Inq_cat_view.php?pageno=$prevpage&psize=$pno' style=color:#383E47> <img src=images/previous_button.PNG border=0></a></td> ";
echo "<td align=center>";
for ($i=1;$i<=$lastpage;$i++)
{
if($i==$pageno)
{
echo "<font size='+2'><a href='Inq_cat_view.php?pageno=$i&psize=$pno' style=color:#383E47> $i</a></font>";
}
else
{
echo "<a href='Inq_cat_view.php?pageno=$i&psize=$pno' style=color:#383E47> $i</a>";
}
}
echo "</td>";
$next=$pageno+1;
echo "<td align=center> <a href='Inq_cat_view.php?pageno=$next&psize=$pno' style=color:#383E47><img src=images/next_button.PNG border=0> </a> ";
}
}
}//end Of numcmp(Record Found)
//else record Not Found
else
{?>
<tr><td align="center"><font color="#3300CC" class="txt" size="+1" style="text-decoration:blink;">No Record Found</font></td></tr>
<?php
}?>
<?php
echo "</tr></table>";
?>
</form>
</body>
<?php
}
?>
but i using form method get not post
please suggest in our code
please implement in our code how writing code in which place.
Edited by Ezzaral because: Added code tags. Please use them to format any code that you post.
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.