Advertisement
Guest User

Untitled

a guest
Jul 29th, 2015
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.64 KB | None | 0 0
  1. <?php
  2.  
  3. error_reporting(-1);
  4. ini_set('display_errors', 'On');
  5. ?>
  6. <?php
  7. $servername = "localhost";
  8. $username = "root";
  9. $password = "tvlgalcslmt06";
  10. $dbname = "accessibilita";
  11.  
  12. try {
  13. $dbh = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
  14. // set the PDO error mode to exception
  15. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  16. echo 'Connected to database<br />';
  17. } catch(PDOException $e) {
  18. echo "Connection failed: " . $e->getMessage();
  19. }
  20.  
  21. $dbh->query("use accessibilita");
  22. ?>
  23. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  24. <html xmlns="http://www.w3.org/1999/xhtml">
  25. <head>
  26. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  27. <title>PHP Delete Data With Javascript Confirmation - By Cleartuts</title>
  28. <script type="text/javascript">
  29. function delete_id(id)
  30. {
  31. if(confirm('Sure To Remove This Record ?'))
  32. {
  33. window.location.href='admin.php?delete_id='+id;
  34. }
  35. }
  36. </script>
  37. </head>
  38. <body>
  39. <center>
  40.  
  41. <div id="header">
  42. <div id="content">
  43. <label>PHP Delete Data With Javascript Confirmation - By Cleartuts</label>
  44. </div>
  45. </div>
  46. <div id="body">
  47. <div id="content">
  48. <table align="center">
  49. <?php
  50. $sth = $dbh->prepare("SELECT * FROM tagesroma");
  51. $sth->execute();
  52. while ($row = $sth->fetch()) {
  53. echo '<td style="width:75%;">';
  54. echo $row['nome'] . "\t";
  55. echo $row['cognome'] . "\t";
  56. echo $row['indirizzo'] . "\t";
  57. echo $row['civico'] . "\t";
  58. echo $row['citta'] . "\t";
  59. echo $row['prov'] . "\n";
  60. echo '<td></tr>';
  61. }
  62. ?>
  63. </table>
  64. <?php
  65. if($delete->fetchColumn() > 0)
  66. {
  67. $id = $_GET['id'];
  68. $delete_id = "DELETE FROM tagesroma WHERE id=:id";
  69. $delete = $dbh->prepare($delete_id);
  70. $delete->bindParam(':id', $id, PDO::PARAM_INT);
  71. $delete->execute();
  72. while($row = $delete->fetch(PDO::FETCH_ASSOC)){}
  73. {
  74. ?>
  75. <tr>
  76. <td><?php echo $row[1]; ?></td>
  77. <td><?php echo $row[2]; ?></td>
  78. <td><?php echo $row[3]; ?></td>
  79.  
  80. <td align="center"></td>
  81. </tr>
  82. <?php
  83. }
  84. }
  85. else
  86. {
  87. ?>
  88. <tr>
  89. <th colspan="4">There's No data found !!!</th>
  90. </tr>
  91. <?php
  92. }
  93. ?>
  94. </table>
  95. </div>
  96. </div>
  97. </center>
  98. </body>
  99. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement