DELETE RECORD FROM DATABASE BY PHP ON WEBPAGE

 DELETE RECORD FROM DATABASE BY PHP ON WEBPAGE

1. DELETE RECORD 

 

(delete.php  )

 

<?php

include_once 'database.php';

$result = mysqli_query($con,"SELECT * FROM emp");

?>

 

<!DOCTYPE html>

<html>

<head>

<link rel="stylesheet" href="style.css">

<title>Delete employee data</title>

</head>

<body>

<table>

          <tr>

          <td>Employee Id</td>

          <td>Employee Name</td>

          <td>Father Name</td>

          <td>City</td>

         

          <td>Action</td>

          </tr>

          <?php

          $i=0;

          while($row = mysqli_fetch_array($result)) {

          ?>

          <tr class="<?php if(isset($classname)) echo $classname;?>">

          <td><?php echo $row["eid"]; ?></td>

          <td><?php echo $row["ename"]; ?></td>

          <td><?php echo $row["fname"]; ?></td>

          <td><?php echo $row["city"]; ?></td>

         

          <td><a href="delete1.php?eid=<?php echo $row["eid"]; ?>">Delete</a></td>

          </tr>

          <?php

          $i++;

          }

          ?>

</table>

</body>

</html>


(delete1.php )

 

<?php

include_once 'database.php';

$sql = "DELETE FROM emp WHERE eid='" . $_GET["eid"] . "'";

if (mysqli_query($con, $sql)) {

    echo "Record deleted successfully";

} else {

    echo "Error deleting record: " . mysqli_error($con);

}

$result = mysqli_query($con,"SELECT * FROM emp WHERE eid='" . $_GET['eid'] . "'");

$row= mysqli_fetch_array($result);

?>

<html>

<head>

<title>Update Employee Data</title>

</head>

<body>

<form name="frmUser" method="post" action="">

<div><?php if(isset($message)) { echo $message; } ?>

</div>

<div style="padding-bottom:5px;">

<a href="retrieve.php">Employee List</a>

</div>

 

 

</form>

</body>

</html>


 ...

================================================

Post a Comment

0 Comments