Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <basefont face="Arial">
- </head>
- <body>
- <?php
- $host = "localhost";
- $user = "root";
- $pass = "akecbdy6";
- $db = "passwd";
- $table = "details";
- // create mysql object
- // open connection
- $mysqli = new mysqli($host, $user, $pass, $db);
- // check for connection errors
- if (mysqli_connect_errno()) {
- die("unable to connect");
- }
- // if id is provided, then delete that record
- if (isset($_GET['id'])) {
- // create query to delete record
- $query = "DELETE FROM $table WHERE id = ".$_GET['id'];
- // execute query
- if ($mysqli->query($query)) {
- // print number of affected
- echo $mysqli->affected_rows." row(s) affected";
- }
- else {
- // print error message
- echo "Error in query: $query. ".$mysqli->error;
- }
- }
- $query = "SELECT * FROM $table";
- // execute query
- if ($result = $mysqli->query($query)) {
- // see if any rows were returned
- if ($result->num_rows > 0) {
- // yes
- // print them one after another
- echo "<table cellpadding=10 border=1>";
- while($row = $result->fetch_array()) {
- echo "<tr>";
- echo "<td>".$row[0]."</td>";
- echo "<td>".$row[1]."</td>";
- echo "<td>".$row[2]."</td>";
- echo "<td><a href=".$_SERVER['PHP_SELF']."?id=".$row[0].">Delete User</a></td>";
- echo "</tr>";
- }
- }
- // free result set memory
- $result->close();
- }
- else {
- // print error message
- echo "Error in query: $query. ".$mysqli->error;
- }
- $mysqli->close();
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement