<?php
session_start();
?>
<html>
<body>
<?php
require_once 'login.php';
$connection=new mysqli($db_hostname, $db_username, $db_password,$db_database);
if (!$connection) die("unable to connect to mysqli:".mysqli_error());
mysqli_select_db($connection,"dbase1")
or die("db not selected".mysqli_error());
$sql=" SELECT * FROM tab";
$result=$connection->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc())
{
?>
<form class="boxed" style ="border: 4px solid black ; text-align: center; action ="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<h1> Message </h1>
<?php
echo "Id: " . $row["id"]. "<br>". "Name: " . $row["name"]. "<br>". " Email : " . $row["email"]. "<br>"."Phone # " . $row["phone"]. "<br>"."Message : " . $row["text"]. "<br>";
?>
<input type="submit" class="button" value="delete" style =" background-color: grey;
border: none;
color: white;
padding: 15px 70px;
margin: 15px 0px;
cursor: pointer;"/>
</form>
<?php
}
}
if(isset($_POST['delete']))
{
$id= $_POST($connection,'id');
$sql=" DELETE FROM tab WHERE id=".$id;
$result=$connection->query($sql);
}
?>
</body>
</html>
This code actually gets data from databse and i want to add a feature if one clicks on delete button the data against that button gets delete for every data set i am making a box with name and more data with delete button all i want is to delete data from db whenever one clicks the delete button and the data against that button i mean a table on that form must need to delete.
Aucun commentaire:
Enregistrer un commentaire