mercredi 22 février 2017

How can I delete only one of the table elements, because if I click it, it will delete any of the entries

Here is my Code

<?php
require '../db/dbcon.php';
$sql="SELECT ClientId,Email,FirstName,LastName,Password,PhoneNumber,AdressID from client;";
$sth = $dbh->prepare($sql);
$sth->execute();
foreach($sth as $row){
    echo "<tr>";
    echo "<td>".$row['FirstName']."</td>";
    echo "<td>".$row['LastName']."</td>";
    echo "<td>".$row['Password']."</td>";
    echo "<td>".$row['Email']."</td>";
    echo "<td>".$row['PhoneNumber']."</td>";
    echo "<td></td>";
    echo "<td></td>";
    echo "<td></td>";
    echo "<td></td>";
    $clientid=$row['ClientId'];
    echo "<form action=\"viewclients.php\" method=\"post\"> ";
    echo "<td><input type=\"submit\" name=\"fshij\" value=\"Fshij\"></td>";
    echo "</form>";
    if(isset($_POST['fshij'])){
        $sql = "DELETE FROM client WHERE ClientId=".$clientid.";";
        $sth = $dbh->prepare($sql);
        $sth->execute();
        header('location:viewclients.php');
    }
    echo "</tr>";
}
?>

After the results are shown in the Webpage, if I click delete in any of these entries it will delete all of them.

Aucun commentaire:

Enregistrer un commentaire