Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

Menambahkan tombol hapus di PHP pada setiap baris tabel MySQL

Cukup menggunakan PHP sebagai berikut (Anda dapat menggunakan JS)

while($book = mysqli_fetch_assoc($records)){

echo "<tr>";
echo "<td>".$book['Staff_ID']."</td>";
echo "<td>".$book['Staff_Name']."</td>";
echo "<td>".$book['Class']."</td>";
echo "<td><a href='delete.php?id=".$book['Staff_ID']."'></a></td>"; //if you want to delete based on staff_id
echo "</tr>";
}// end while loop

Di delete.php . Anda berkas,

$id = $_GET['id'];
//Connect DB
//Create query based on the ID passed from you table
//query : delete where Staff_id = $id
// on success delete : redirect the page to original page using header() method
$dbname = "your_dbname";
$conn = mysqli_connect("localhost", "usernname", "password", $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

// sql to delete a record
$sql = "DELETE FROM Bookings WHERE Staff_ID = $id"; 

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


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. MySQL menyimpan waktu durasi - tipe data?

  2. Hapus dengan Gabung di MySQL

  3. SQLSTATE[42S22]:Kolom tidak ditemukan:1054 Kolom 'id' tidak diketahui di 'where clause' (SQL:pilih * dari `songs` di mana `id` =5 batas 1)

  4. Cara Menyisipkan data dari satu tabel database ke tabel database lain di Mysql

  5. Cari posisi teks, ekstrak teks dan masukkan di kolom baru di MySQL