Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(-1);
- ini_set('display_errors', 'On');
- ?>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "tvlgalcslmt06";
- $dbname = "accessibilita";
- try {
- $dbh = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
- // set the PDO error mode to exception
- $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- echo 'Connected to database<br />';
- } catch(PDOException $e) {
- echo "Connection failed: " . $e->getMessage();
- }
- $dbh->query("use accessibilita");
- ?>
- <!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>PHP Delete Data With Javascript Confirmation - By Cleartuts</title>
- <script type="text/javascript">
- function delete_id(id)
- {
- if(confirm('Sure To Remove This Record ?'))
- {
- window.location.href='admin.php?delete_id='+id;
- }
- }
- </script>
- </head>
- <body>
- <center>
- <div id="header">
- <div id="content">
- <label>PHP Delete Data With Javascript Confirmation - By Cleartuts</label>
- </div>
- </div>
- <div id="body">
- <div id="content">
- <table align="center">
- <?php
- $sth = $dbh->prepare("SELECT * FROM tagesroma");
- $sth->execute();
- while ($row = $sth->fetch()) {
- echo '<td style="width:75%;">';
- echo $row['nome'] . "\t";
- echo $row['cognome'] . "\t";
- echo $row['indirizzo'] . "\t";
- echo $row['civico'] . "\t";
- echo $row['citta'] . "\t";
- echo $row['prov'] . "\n";
- echo '<td></tr>';
- }
- ?>
- </table>
- <?php
- if($delete->fetchColumn() > 0)
- {
- $id = $_GET['id'];
- $delete_id = "DELETE FROM tagesroma WHERE id=:id";
- $delete = $dbh->prepare($delete_id);
- $delete->bindParam(':id', $id, PDO::PARAM_INT);
- $delete->execute();
- while($row = $delete->fetch(PDO::FETCH_ASSOC)){}
- {
- ?>
- <tr>
- <td><?php echo $row[1]; ?></td>
- <td><?php echo $row[2]; ?></td>
- <td><?php echo $row[3]; ?></td>
- <td align="center"></td>
- </tr>
- <?php
- }
- }
- else
- {
- ?>
- <tr>
- <th colspan="4">There's No data found !!!</th>
- </tr>
- <?php
- }
- ?>
- </table>
- </div>
- </div>
- </center>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement