-4
$query = "SELECT * FROM categories";
$select_categories = mysqli_query($connection, $query);

while ($row = mysqli_fetch_assoc($select_categories)) {
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];

echo "<tr>";
echo "<td>{$cat_id}</td>";
echo "<td>{$cat_title}</td>";
echo "<td><a href='categories.php?delete={$cat_id}'>Delete</a></td>";
echo "</tr>";

}

?>

<?php 

//DELETE QUERY;

if(isset($_GET['detele'])) {

$the_cat_id = $_GET['delete'];
$query = "DELETE FROM categories WHERE cat_id = {$the_cat_id} ";
$delete_query = mysqli_query($connection,$query);
header("Location: categories.php");
}

?>     

So, I have this page that is showing me every single item (category) from my database, and I have them sorted by id and everything works just fine except only one thing. When I try to delete an item, nothing happens. The thing is I have no errors and that is making me wander why is not working.

  • 3
    Note: Your code is *wide open* to **SQL injection attacks**. You're basically allowing users to execute any code they want on your database. – David Nov 06 '15 at 13:15
  • I know. Right now I'm learning php and nothing more and before security I want to learn the basics. – Leontin Andrei Nov 06 '15 at 13:28
  • Security *is* "the basics". Why would you intentionally learn to do things *poorly*? "I'll fix it later" is the most damaging and pervasive delusion in all of software development. – David Nov 06 '15 at 13:30
  • Dude, relax. I'm watching a tutorial about this. If you can recommand something better for a beginner, please do. I've seen something about security and that area will be covered later on. I do not know why, but this is the way it was created. :) – Leontin Andrei Nov 06 '15 at 13:36

2 Answers2

4

might be spelling mistake in if(isset($_GET['detele'])), detele should be delete check your code

Thamilhan
  • 13,040
  • 5
  • 37
  • 59
Sugumar Venkatesan
  • 4,019
  • 8
  • 46
  • 77
0

Yes spelling mistake so it will never go into condition and never run delete query. Please correct it and confirm.

Incorrect :

if(isset($_GET['detele']))

Correct:

if(isset($_GET['delete']))
RJParikh
  • 4,096
  • 1
  • 19
  • 36