Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

311
Views
Delete button doesn't work in table rows

I am trying to add a delete button on each row so that I can delete a record when the button is pressed. But the delete function doesn't work and shows "Error deleting record". I don't know where the problem is.

Please help me. Any help would be appreciated.

Here is my code:

managetimetable.php

<?php 
include("include/config.php");

$sql = "SELECT * FROM `time_table`";
$query = mysqli_query($link,$sql) or die(mysqli_error($link));    
?>

<table width="70%" cellpadding="5" cellspacing="5">
  <tr>
    <th><strong>ID</strong></th>
    <th><strong>Image</strong></th>
    <th></th>
  </tr>

  <?php while ($row = mysqli_fetch_array($query)) : ?>
    <tr>
      <td><?php echo $row['t_id']; ?></td>
      <td><?php echo $row['t_name']; ?></td>
      <td><a href='delete.php?id=".$row['t_id']."'>Delete</a></td>
    </tr>
  <?php endwhile; ?>
</table>

delete.php

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

include("include/config.php");

$sql = "DELETE FROM time_table WHERE t_id = $id"; 

if (mysqli_query($link, $sql)) {
    mysqli_close($link);
    header('Location: index.php');
    exit;
} else {
    echo "Error deleting record";
}
?>

config.php

<?php $link=mysqli_connect("localhost","root","","course_registration_system"); ?>

My database: Time_table

t_id  t_name                    t_image 
8     course_offered_2017.jpg   [BLOB - 246.1 KiB]
9     time_table_2017.jpg       [BLOB - 446.4 KiB]
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Replace this

   <td><a href='delete.php?id=".$row['t_id']."'>Delete</a></td>

with

   <td><a href='delete.php?id=<?php echo $row["t_id"];?>'>Delete</a></td>

*Try to use pdo

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!