Friday, 19 July 2019

student project-4


First we are try for delete
<html>
<head>
<style>
table,th,td
{
        border:1px solid blue;
}
th{
        background-color:red;
}
th,td{
        height:50px;
        width:90px;
}
</style>
</head>
<body>
<table border="1">
<tr><th colspan="8">view all records</th></tr>
<tr><td>Roll No.</td><td>Name</td>
<td>email</td><td>website</td>
<td>gender</td>
<td>edit</td>
<td>delete</td>
<td>details</td></tr>


<?php
$conn= new mysqli("localhost","root","","student3");
$sql="SELECT * FROM details";

$result=$conn->query($sql);
while($row=$result->fetch_assoc()){
        $id=$row['roll'];
        echo "<table border='1'>";
        echo "<tr><td>".$row['roll']."</td><td>".$row['Name']."</td>";
        echo "<td>".$row['Email']."</td>";
        echo "<td>".$row['Website']."</td>";
echo "<td>".$row['Gender']."</td>";
echo "<td><a href = 'edi.php?edit=<?php echo $id; ?>'>Edit</a></td>
  <td><a href='del.php?id=".$row['roll']."'>del</a></td>
<td>details</td></tr>";
}
echo "</table>";

?>

Del.php
<?php
$id = $_GET['id'];

$conn= new mysqli("localhost","root","","student3");

if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "DELETE FROM details WHERE roll = $id";

if (mysqli_query($conn, $sql)) {
    mysqli_close($conn);
    header('Location: viewrecord.php'); //If book.php is your main page where you list your all records
    exit;
} else {
    echo "Error deleting record";
}

?>

No comments:

Post a Comment