Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- delete.php
- <?php
- $host ="localhost";
- $user = "root";
- $pass = "";
- $db_name = "test_son";
- $table = "test";
- //Connect to MySQL and select database
- $connection = mysqli_connect($host, $user, $pass, $db_name);
- //Check if connection errors
- if (mysqli_connect_errno()){
- die ("An error while connecting to MySQL" . mysqli_connect_errno());
- }
- //Select record from mysql
- $select_query = "select * from $table";
- $result = mysqli_query($connection, $select_query);
- ?>
- <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
- <tr>
- <td colspan="5" bgcolor="#FFFFFF"><strong>Delete data in mysql</strong> </td>
- </tr>
- <tr>
- <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td>
- <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td>
- <td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td>
- <td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td>
- <td align="center" bgcolor="#FFFFFF"> </td>
- </tr>
- <?php
- while ($rows = mysqli_fetch_array($result)){
- ?>
- <tr>
- <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
- <td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td>
- <td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td>
- <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td>
- <td bgcolor="#FFFFFF"><a href="delete_ac.php?id=<? echo $rows['id']; ?>">delete</a></td>
- </tr>
- <?php
- // close while loop
- }
- ?>
- </table>
- <?php
- //Close connection
- mysqli_close($connection);
- ?>
- -------------------------
- delete_ac.php
- -------------------------
- <?php
- $host ="localhost";
- $user ="root";
- $pass = "";
- $db_name = "test_son";
- $table = "test";
- //Connect to server and select database
- $connection = mysqli_connect($host, $user, $pass, $db_name);
- //Check if connection errors?
- if (mysqli_connect_errno()){
- die("Connection error has occurred" . mysqli_errno());
- }
- //get value of id that sent from address bar
- $id=$_GET['id'];
- //Delete data in mysql from row that has this id
- $sql="delete from $table where id='$id'";
- $result = mysqli_query($connection, $sql);
- //If successfully deleted
- if ($result){
- echo "deleted successfully";
- echo "<BR>";
- echo "<a href='delete.php'> Back to Main Page</a>";
- }
- else {
- echo "ERROR OCCURRED " . mysqli_errno($connection);
- }
- ?>
- <?php
- //close php connection
- mysqli_close($connection);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement