PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 2, 2022

[FIXED] How to Echo delete link into php?

 August 02, 2022     echo, html, html-table, mysql, php     No comments   

Issue

I need to delete a row but I can't do it. Tell me please, how can this be done?

$id=0;
while ($row=$res->fetch_assoc())
{
$id++;
echo "<tr>";
echo "<td>{$id}</td>";
echo "<td>{$row["BTITLE"]}</td>";
echo "<td>{$row["KEYWORDS"]}</td>";
echo "<td><a href='{$row["FILE"]}' 
target='_blank'>View</a></td>";
echo "<td><a href='view_books.php?id={$id}'>Delete</a></td>";
echo "</tr>";
}

I added

<?php
    session_start();
    include "database.php";
    if(!isset($_SESSION["AID"]))
    {
        $id=$_GET['id'];
        $delete=mysqli_query($conn, "DELETE FROM `book` WHERE `BID`='$id'");
        header("location:alogin.php");
        die();
    }
?>

Where is my mistake?


Solution

Create a file delete.php that accept as parameter an id to delete. Then delete the row from table that corresponds to that id. I assume you can do it, if not, take some hints from file $row["FILE"].

Now your loop should look like:

while ($row=$res->fetch_assoc())
{
  $i++;
  echo "<tr>";
  echo "<td>{$i}</td>";
  echo "<td>{$row["BTITLE"]}</td>";
  echo "<td>{$row["KEYWORDS"]}</td>";
  echo "<td><a href='{$row["FILE"]}' target='_blank'>View</a></td>";
  echo "<td><a href='delete.php?id={$i}'>Delete</a></td>";
  // OR, better if you know what it means:
  echo "<td><a href='delete.php?id={$row["id"]}'>Delete</a></td>";
  echo "</tr>";
}


Answered By - IT goldman
Answer Checked By - David Marino (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing