php deleting multiple data using check box
<!--data base-->
CREATE TABLE `user_check` (
`id` int(50) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=0;
<!--data base close-->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<SCRIPT language="javascript">
$(function(){
// add multiple select / deselect functionality
$("#selectall").click(function () {
$('.case').attr('checked', this.checked);
});
$(".case").click(function(){
if($(".case").length == $(".case:checked").length) {
$("#selectall").attr("checked", "checked");
} else {
$("#selectall").removeAttr("checked");
}
});
});
</SCRIPT><?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="online"; // Database name
$tbl_name="user_check"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
$count=mysql_num_rows($result);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td><form name="form1" method="post" action="">
<table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<td bgcolor="#FFFFFF"> </td>
<td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td>
</tr>
<tr>
<td align="center" bgcolor="#FFFFFF" cellpadding="3">select all<input type="checkbox" id="selectall"/></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" class="case" type="checkbox" value="<?php echo $rows['id']; ?>"></td>
<td bgcolor="#FFFFFF"><?php echo $rows['id']; ?></td>
</tr>
<?php
}
?>
<tr>
<td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" value="Delete"></td>
</tr>
<?php
// Check if delete button active, start this
$delete=$_POST['delete'];
$checkbox=$_POST['checkbox'];
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}
// if successful redirect to sucess.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=sucess.php\">";
}
}
mysql_close();
?>
</table>
</form>
</td>
</tr>
</table>
x-xmax
Country UNITEDSTATES
City Ohio
Posted On 13/04/2012
5
Other Pages
- php word limit
- sql replace
- PHP prepend leading zero before single digit number
- All About Mysql with example advance query
- jquery add new input field
- WordPress Get Specific Page content
- WordPress Get resent post
- php whois domain checking simple script
- simple css horizontal menu code
- youtube php api to reading title & length
- div Tab menu using CSS
- Textarea resize on hove and mouse click
- Create Tab Menu Using Div
- simple javascript lightbox code
- Renaming & reading file name using .bat
- simple jquery slider code
- rewrite rules htaccess or how to create short url in php
- php Set Timezone by country
- javascript new tab on popup window code
- simple jquery for date picker
- php remove spacial characters
- single page website
- simple dropdown menu without javascript
- php deleting multiple data using checkbox
- SELECT OR DESELECT Multiple Checkbox
- php image re-size script
- php read file from directory
- php connect to mysql
- PHP tips and tricks
- Get and output the source of the homepage of a website
- php login scrpit
- php image watermark script
- PHP to Force a File Download
- php pagination script
- Use a javascript confirm box to ask the user if they want to delete
- simple php file upload code
- How to set a div to auto adjust it's height with available browser height
- php script send email with attachment
- Testing interview questions and answers
- Mysql interview questions and answers
- CSS3 interview questions and answers
- HTML5 interview questions and answers
- PHP interview questions and answers
- How do I clear all the entries from just one table in MySQL with PHP
- PHP Reading a file line by line
- filter email id from a string
- php mysql how to get unique data from table
- php how to short array by alphabetical order
- javascrpit iframe break code
- php defining maximum character of string
- php Remove extension from a filename
- Do you know you can watch Star wars Text movie from your computer.
- Interesting Computer tricks -- try it
- how to Clear default value of text input using Javascript
- improve your internet speed using gpedit.msc
- php xml site map script