Hi i had a big database and need to delete and add to it daily. About 500 rows are there in that table. I add add a check box in every row ( in the output page ) .. Something like this

<table>
<?php
$select=select * from table ;
while($row=mysql_fetch_array($select)){;
?>

////// result will come here. Each row contains a check box with a value "id" . Which is from the column id from the database ..and name from 1,2,3.... 

<?php } ?>
</table>

Now i need to check multiple check boxes and press delete button in the php page. Then the values posted to "process.php" and then delete the rows with "id" s of checked....
I tried many but ...
Please any one help me....
Thanks
Rajeesh

Recommended Answers

All 4 Replies

make the checkbox name "id[]" and then you can process the data using

foreach( $_POST['id'] as $key => $val ) {
  //delete query using $val as $id
}

thats just a simple example, there still are some security issues to take care of

Thanks for your support... Please let me know what are the security issues ?

sql injection, xss attacks, ect.

just run is_numeric and mysql_real_escape_string on $val

hi, this is a code for deleteing the entire row from database if we enter the word.... but this code is not working....so reply me as early as possible....

<?php
   
      if($_POST[Word]=="")
	  {
	       echo "<br><br><br><br>
                                               <b>Enter the data in the form</b></font><center>";
	       echo "<center>";
	       echo "<form >";
	       echo "<br>";
	       echo "<br>";echo "<br>";echo "<br>";
	       echo "<center><input type=\"button\" onClick=\"history.go(-1)\"name=\"INSERT\"                                                 Value=\"GoBack\"></center>";
	       echo "</form>";
	       echo "</center>";
                       exit;	
	  }
     else
               {
	      $con = mysql_connect("localhost","root","");
	         if (!$con)
  	          {
 	           die('Could not connect: ' . mysql_error());
   	          }
	      mysql_select_db("my_dict", $con);

$sqlQuery = "DELETE * FROM dic WHERE Word='$_POST[Word]'";
	
          
	if (!mysql_query($sqlQuery,$con))
	{
  	die('Error: ' . mysql_error());
 	 }
                  
                  if ($sqlQuery == TRUE) 
                   {
                       echo" <br>";
	       echo"<br>";
	       echo"<br>";
                       echo"<br>"; 
                       echo "<center><font size=5 color=green><b><br><br>Data deleted successfully</b></font>
                                 </center>";
 	       echo" <br>";
	                          echo"<center><input type=\"button\" onClick=\"history.go(-1)\"name=\"INSERT\" Value=\"To                                                    Insert The Data  GoBack\"></center>";
	     
                  }
 	else
                    {
                      echo " <center><font size=5 color=green>Data could no deleted</b></font></center>";
                    } 

	 mysql_close($con);
            }   //else end
?>
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.