Mysql row delete using php

Reply

Join Date: Sep 2008
Posts: 159
Reputation: rajeesh_rsn is an unknown quantity at this point 
Solved Threads: 0
rajeesh_rsn rajeesh_rsn is offline Offline
Junior Poster

Mysql row delete using php

 
0
  #1
Mar 23rd, 2009
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
Last edited by rajeesh_rsn; Mar 23rd, 2009 at 11:15 pm. Reason: mistake
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,237
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 171
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Mysql row delete using php

 
0
  #2
Mar 23rd, 2009
make the checkbox name "id[]" and then you can process the data using
  1. foreach( $_POST['id'] as $key => $val ) {
  2. //delete query using $val as $id
  3. }
thats just a simple example, there still are some security issues to take care of
Last edited by kkeith29; Mar 23rd, 2009 at 11:39 pm.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 159
Reputation: rajeesh_rsn is an unknown quantity at this point 
Solved Threads: 0
rajeesh_rsn rajeesh_rsn is offline Offline
Junior Poster

Re: Mysql row delete using php

 
0
  #3
Mar 24th, 2009
Thanks for your support... Please let me know what are the security issues ?
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,237
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 171
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Mysql row delete using php

 
0
  #4
Mar 24th, 2009
sql injection, xss attacks, ect.

just run is_numeric and mysql_real_escape_string on $val
Reply With Quote Quick reply to this message  
Join Date: Mar 2009
Posts: 6
Reputation: hemasow is an unknown quantity at this point 
Solved Threads: 0
hemasow hemasow is offline Offline
Newbie Poster

Re: Mysql row delete using php

 
0
  #5
Mar 31st, 2009
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....


  1. <?php
  2.  
  3. if($_POST[Word]=="")
  4. {
  5. echo "<br><br><br><br>
  6. <b>Enter the data in the form</b></font><center>";
  7. echo "<center>";
  8. echo "<form >";
  9. echo "<br>";
  10. echo "<br>";echo "<br>";echo "<br>";
  11. echo "<center><input type=\"button\" onClick=\"history.go(-1)\"name=\"INSERT\" Value=\"GoBack\"></center>";
  12. echo "</form>";
  13. echo "</center>";
  14. exit;
  15. }
  16. else
  17. {
  18. $con = mysql_connect("localhost","root","");
  19. if (!$con)
  20. {
  21. die('Could not connect: ' . mysql_error());
  22. }
  23. mysql_select_db("my_dict", $con);
  24.  
  25. $sqlQuery = "DELETE * FROM dic WHERE Word='$_POST[Word]'";
  26.  
  27.  
  28. if (!mysql_query($sqlQuery,$con))
  29. {
  30. die('Error: ' . mysql_error());
  31. }
  32.  
  33. if ($sqlQuery == TRUE)
  34. {
  35. echo" <br>";
  36. echo"<br>";
  37. echo"<br>";
  38. echo"<br>";
  39. echo "<center><font size=5 color=green><b><br><br>Data deleted successfully</b></font>
  40. </center>";
  41. echo" <br>";
  42. echo"<center><input type=\"button\" onClick=\"history.go(-1)\"name=\"INSERT\" Value=\"To Insert The Data GoBack\"></center>";
  43.  
  44. }
  45. else
  46. {
  47. echo " <center><font size=5 color=green>Data could no deleted</b></font></center>";
  48. }
  49.  
  50. mysql_close($con);
  51. } //else end
  52. ?>
Last edited by peter_budo; Mar 31st, 2009 at 2:44 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2707 | Replies: 4
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC