0

I need to delete news articles from database using a delete button. I have written all the code but it gives me error Notice: Undefined index: acticleID in C:\XAMPP\htdocs\PortalZaVijesti\php\delete.php on line 5. I don't see what is wrong so can you look at my code? Admin.php

$dbc = mysqli_connect("localhost", "root", "", "news_portal") or die(mysql_error());
        $query = "SELECT * FROM news_site;";
        $result = mysqli_query($dbc, $query);
        while ($row = mysqli_fetch_assoc($result)) {
            echo "<p>".$row['title']; 
            echo "</p>
                <form action='php/delete.php' method='post' class='deletePHP'>
                    <input type='hidden' name='articleID' value='".$row['id']."'/>
                    <input type='submit' name='delete' value='delete'/>
                </form>;

delete.php

$dbc = mysqli_connect("localhost", "root", "", "news_portal") or die(mysql_error());
    if(isset($_POST["delete"]) && !empty($_POST["articleID"])){
        $id = mysqli_real_escape_string($dbc, $_POST["acticleID"]);
    }

    $delquery = "DELETE FROM news_site WHERE ID='$id'";
    mysqli_query($dbc, $delquery) or die(mysqli_error($dbc));

    if(mysqli_affected_rows($dbc)){
        echo "It was really successful.";
    }

2 Answers 2

2

I can see a typing error in delete.php.

On line 3 of the code shown, "articleID" is spelt as "acticleID". This is why you are getting an Undefined index.

Change:

$id = mysqli_real_escape_string($dbc, $_POST["acticleID"]);

to:

$id = mysqli_real_escape_string($dbc, $_POST["articleID"]);
Sign up to request clarification or add additional context in comments.

Comments

2

Please fix the line

$id = mysqli_real_escape_string($dbc, $_POST["acticleID"]);

to

$id = mysqli_real_escape_string($dbc, $_POST["articleID"]);

You have mistyped the articleId

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.