Delete mySQL table from php link not working (Blank page appears)

518

I've listed a list of rows from my mySQL database onto an admin page. I now simply want to add an icon beside each row giving the user the option to delete the row in question.

Here's my php delete link:

<a href="delete.php?action=delete&id='$id'"><i class="icon-circle-blank"></i></a>

And my delete.php file looks like:

<?php

require_once 'db.php';
global $con;


    if(($_GET['action'] == 'delete') && isset($_GET['id'])) {

    $id = $_GET['id'];
    $sql = "DELETE FROM quotes WHERE id = '$id'";
    $query = mysqli_query($con, $sql);

}

header("location: http://localhost:81/logintest/home.php");

    mysqli_close($con);

?>

From some reason when I click the link, the page just returns a blank page with no database rows being deleted. What am I overlooking?

404

Answer

Solution:

Unless you're showing us a pseudo-code, this will not parse the PHP id variable:

delete.php?action=delete&id='$id'

you need either:

delete.php?action=delete&id=<?= $id ?>

or

delete.php?action=delete&id=<?php echo $id; ?>

People are also looking for solutions to the problem: html - Table Province District and Subdistrict with PHP

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.