Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa PHP delete row
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


sourabh parihar
delete row
1 Answer(s)      2 years and 3 months ago
Posted in : PHP


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>

Advertisement
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()); 
    }
    %>


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
insert and delete a row programmatically
insert and delete a row programmatically  How to insert and delete a row programmatically ? (new feature in JDBC 2.0
Advertisements
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
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
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 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
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
Hibernate delete a row error - Hibernate
Hibernate delete a row error  Hello, I been try with the hibernate delete example (http://www.roseindia.net/hibernate/hibernate-delete.shtml...(); //======================================= sess = fact.openSession(); String hql = "delete from Contact contact
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
Update delete perticular row from brower on link - Struts
Update delete perticular row from brower on link   how can update and delete perticular row from List of employee in brower format are ramesh... delete when i click on update than that perticular row are display on another
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
Delete and add row from Table View iPhone
Delete and add row from Table View iPhone In this tutorial will learn how to delete and also how to add row into the table view iPhone, with the help of edit... and Delete buttons on Table view. Table views are commonly found in iPhone applications
Delete row and column from table through java code
Delete row and column from table through java code... will see how to delete row and column from given table through java code. Java code... will delete the row having minimum value of ID then delete the column named
Deleting row and column from a table
Deleting row and column from a table  In this program ,we delete row... connection interface and java driver. After it we can delete row using "delete... the row having minimum ID.  statement.executeUpdate("delete from cellular where id
Delete a Specific Row from a Database Table
Delete a Specific Row from a Database Table   ... in a row, now we need to delete that wrong data. This can be done very easily, and in this section we are going to do the same that is, how to delete a specific row
delete
delete  how delete only one row in the database using jsp.database... type="button" name="edit" value="Delete" style="background-color:red;font-weight... = conn.createStatement(); st.executeUpdate("DELETE FROM employee WHERE empid
DELETE
DELETE   I AM DOING IT IN MYSQL. DELETE FROM EMP WHERE SAL>(SELECT SAL FROM EMP WHERE ENAME='MILLAR') AND ENAME='ALLEN'; THIS IS GIVING THE FOLLOWING ERROR Error Code : 1093 You can't specify target table 'EMP
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
ADD ROW - JSP-Servlet
ADD ROW  Hi Sir, How to use add row and delete row concept in jsp .  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/add-element.shtml Thanks
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
Advertisements
 

 

 

DMCA.com