delete row

Ads
 

delete row

how to delete row using checkbox and button in php?

localhost=wampserver database name=sourabh table name=sonu and my code is .....

<?php

$link=mysql_connect("localhost", "root", "");
mysql_select_db("sourabh", $link);


$rows=mysql_query("select * from sonu");
$row=mysql_fetch_array($rows);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>delete2</title>
</head>
<form action="delete2.php" method="post" name="delete" >
<table width="100%" border="1">
<tr><td>select</td>
    <td>NAME</td>
    <td>Father NAME</td>
     <td>Date Of Birth</td>
      <td>Mobile</td>
       <td>Email</td>
        <td>Address</td>

  </tr>
  <?php  while($row=mysql_fetch_array($rows))
{  ?>
  <tr>
    <td><input  type="checkbox" name="checkbox[]" id="checkbox[]" value="<?php echo $row['id'];?>"></td>
    <td><?php echo $row['name']; ?></td>
    <td><?php echo $row['fathername']; ?></td>
     <td><?php echo $row['dob']; ?></td>
      <td><?php echo $row['mobile']; ?></td>
       <td><?php echo $row['email']; ?></td>
        <td><?php echo $row['address']; ?></td>

  </tr>
<?php } ?>

</table>
<input type="submit" name="delete" value="delete"  />

<?php 
if(isset($_POST['delete']))
{
    for($i=0;$i<$row;$i++)
    {
    $delete = $checkbox[$i];
    mysql_query("delete from sonu where id='$delete'");

    }
}

?>
</form>
<body>
</body>
</html>
View Answers

September 4, 2012 at 6:05 PM

We are providing you the jsp code that displays the database table data into the html table. Along each table row there is a checkbox consists of id of table. When the user selects the particular checkbox, that row will get deleted from the database. In the database we have created three fields bookid,author and title in the database.

1) Create book.jsp

<%@page import="java.sql.*"%>

<form name=myname method=post action="delete.jsp">
<table border="1">
<tr><td></td>
<td><b><u>bookid</u></b></td>
<td><b><u>Author</u></b></td>
<td><b><u>title</u></b></td>
</tr>
<%try{

Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root", "root");
ResultSet rs = null;
Statement st=null;
st=conn.createStatement();
rs = st.executeQuery("select * from book");
int i=0; while(rs.next()){ %>
<tr><td><input type="checkbox" name="check<%=i%>" value=<%= rs.getString("bookid") %>></td>
<td><%= rs.getString("bookid") %></td>
<td><%= rs.getString("author") %></td>
<td><%= rs.getString("title") %></td>
</tr><%
i++;
}
}catch(SQLException e){ System.out.println(e.getMessage()); } %>
</table>
<input type="submit">
</form>

2) Create delete.jsp

<%@page import="java.sql.*"%>

<%String id[]= new String[10];
for(int i=0;i<10;i++){
id[i]=request.getParameter("check"+i);
out.println(id[i]);
}
%>

<%try{

Connection conn = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mysql","root", "root");
ResultSet rs = null;
Statement st=null;
st=conn.createStatement();
for(int a=0;a<10;a++){
st.executeUpdate("delete from book where bookid='"+id[a]+"'");

}
}catch(SQLException e){ 
    System.out.println(e.getMessage()); 
    }
    %>

Ads









Related Tutorials/Questions & Answers:
delete row
delete row  how to delete row using checkbox and button in php... if(isset($_POST['delete'])) { for($i=0;$i<$row;$i++) { $delete...("sourabh", $link); $rows=mysql_query("select * from sonu"); $row=mysql
sqlite database delete row
sqlite database delete row  How to delete row from SQLite Database?    NSString *updateSQL = [NSString stringWithFormat: @"DELETE FROM aListDB WHERE id='%@'",details.ids
Advertisements
delete row using id
delete row using id  package pkg2; import org.hibernate.Query; import... = "delete from Insurance insurance where id = 2"; Query query = sess.createQuery(hql); int row = query.executeUpdate(); if (row == 0
delete row from a table in hibernate
delete row from a table in hibernate  is there method to delete row in a table using hibernate like save(-) to insert row
delete multiple row using checkbox
delete multiple row using checkbox  how to delete multiple row in a table which is connected to database using checkbox
delete multiple row using checkbox
delete multiple row using checkbox  how to delete multiple row in a table which is connected to database using checkbox
uitableview manually delete row
uitableview manually delete row  uitableview manually delete row   NSMutableIndexSet *indexes = [NSMutableIndexSet indexSet]; [array removeObjectAtIndex:indexPath.row]; if(![array count]) [indexes addIndex
Delete a row from database by id
Delete a row from database by id  I m creating a small application...) for "DELETE" AND "UPDATE". On clicking delete which is hyper link that particular row.... So anyone will tell me how to give hyper link to Delete and Update and delete
how to delete a row in sql without using delete command.
how to delete a row in sql without using delete command.  how to delete a row in sql without using delete command. thanks in advance
delete multiple row using checkbox
delete multiple row using checkbox  delete multiple row using checkbox   We are providing you the code where we have specified only three...; st=conn.createStatement(); for(int a=0;a<10;a++){ st.executeUpdate("delete
data grid with edit and delete options at each row.
data grid with edit and delete options at each row.  i want to display the table data in the format of data grid with edit and delete options at each row. i need it very urgently. advance thanks
delete row from a table using hibernate
delete row from a table using hibernate  //code in java file String hql="delete from CONTACT c where ID=6"; Query query=session.createQuery... [delete from CONTACT] int i=query.executeUpdate
How to delete the row from the Database by using servlet
How to delete the row from the Database by using servlet  Dear Sir/Madam I am trying to delete the one user data in the Oracle SQL server database...: Delete row from database using servlet   In that link solution
JDBC Delete Row In Table Example
JDBC Delete Row In Table Example : In this tutorial we will learn how delete... or more specific  row delete from table that follow any given condition...; delete row then count deleted row and display output "Deleted specific
JDBC ResultSet Delete Row Example
JDBC ResultSet Delete Row Example: Learn how to delete row using ResultSet. We are also used ResultSet object with update capability for delete rows from.... 6. Finally call deleteRow() ResultSet method for delete the current row form
include a delete option in every row of table in a JSP page
include a delete option in every row of table in a JSP page  I have the following code of a JSP page........... <blockquote> <p>... on Delete it should delete the particular record from the database and reflect
How to delete the row from the Database by using while loop in servlet
How to delete the row from the Database by using while loop in servlet  Dear Sir/Madam, I am trying to delete the one user data in the Oracle SQL... are USERS (Char), PASS (Varchar2) and CODE (Varchar2). I am trying to delete 4th user
JDBC: Delete Record using Prepared Statement
JDBC: Delete Record using Prepared Statement In this section, we will discuss how to delete row of a table using Prepared Statements. Delete Record ... Clause. So you can delete one row or multiple row of table as specified
Deleting a Row from SQL Table Using EJB
are going to delete a row from the SQL Table. Find out the steps given below that describes how to delete a particular row from the database table using EJB... Deleting a Row from SQL Table Using EJB
Delete Account
Delete Account  How to delete account
row_id
row_id  sir i have created a table my_table with two rows n two column with smillar name in each cell without any primary key , how can i change the first row and third column's name in sql server 2005 , kindly send me the query
row_id
row_id  sir i have created a table my_table with two rows n two column with smillar name in each cell without any primary key , how can i change the first row and third column's name in sql server 2005 , kindly send me the query
Hibernate delete example program
Hibernate delete example program  How to delete an object in Hibernate? In my program I have to write program to delete the data using Hibernate framework. I want to delete one row of data who's primary key is known to me. What
Sql delete operation
press delete link the appropriate row will be deleted.but i am get this answer...Sql delete operation  Hi, I am tried to several times but i am... yyyy 95643663 update delete 2 aaaa bbbb 64645666
delete record
delete record  how to delete record using checkbox and button in php... data into the html table. Along each table row there is a checkbox consists of id of table. When the user selects the particular checkbox, that row will get
Grid rows delete issue
event of dropdown also,so if we delete middle row and then remove all rows on onchange of dropdown then because of rows indexing issue,they can't get middle row...Grid rows delete issue  I have a grid having rows with Remove button
To delete post
To delete post  How can I delete my old post answer. I've posted 2 same answers by mistake
Use of delete() method in hibernate.
Use of delete() method in hibernate.  Define the use of delete() method of hibernate?   Hibernate provide the facility to delete one row or multiple row from a table. Here is an example. Example: package
Modifying a single row of database based on selection in jsp
or delete the selected row and update to database.. Please provide me a solution...-and-delete-options-at-each-row-.html http://www.roseindia.net/answers/viewqa/JSP...Modifying a single row of database based on selection in jsp  Hi guys
didSelectRowAtIndexPath deselect row
didSelectRowAtIndexPath deselect row  Hi, In my UITableView application when user taps a row, how to deselect row? Thanks
jtable insert row swing
jtable insert row swing  How to insert and refresh row in JTable?   Inserting Rows in a JTable example

Ads