I have a Table that displays titled and first name columns and delete link on the 3rd column.

Unfortunately for a reason i don't understand, records are not deleting when the Delete link is clicked.

Please friends, help me figure out what's wrong here.

Table
<?php 

  $user_id = $_SESSION["user_id"]; //brought here via 
                                    session
   //select statement here
  // output data of each row
  while($row = $result->fetch_assoc()) {

    echo '<tr> <td scope="row">' . $row["titled"]. '</td> <td> '.$row["firstname"] .'</td> <td><a href="user_delete.php? 
                  delete=$row[user_id]">Delete</a> </td> </tr>';
   }

   } else {
   echo "0 results";
   }

   ?>    

user_delete.php code

  <?php
session_start();
require_once $_SERVER['DOCUMENT_ROOT'] . '/soap/includes/server.php';

if(isset($_GET["delete"]) )
{
    $user_id = $_GET["delete"];
    $sql= "DELETE FROM users WHERE user_id='$user_id'";
    $res= mysqli_query($con, $sql) or 
    die("Failed".mysqli_error($con));
    echo "<meta http-equiv='refresh' 
    content='0;url=user_settings.php'>";
}
?> 

Recommended Answers

All 2 Replies

GET is never a good idea for operations that alter data in a db. You'd be better to use POST. Obviously this would entail buttons and multiple forms for normal forms, but you could leverage Ajax to send ID data via POST. This has the advantage of no page redirect. There are a few ways to do this though. Also you are open to sql injection as you don't sanitize your input data nor do you use prepared statements.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.