deleting a row from table

Nathanus

I'm trying to make a delete link, when i click on it it will delete a row from sql table with given ID, it should go like this, but it's not working, can you please take a look at my code and tell me what am I doing wrong, thanks !

This is what the link, when i click on archive it should delete the row.

echo '<td><a href="archivenews.php?newsid='. $row['ID'] .'">Arhiviraj</a>/<a href="archivenews.php?newsid='. $row['ID'] .'">Obrisi</a></td>';

and this is archivenews.php

<?php
    session_start();
    require('konektor.php');

    if(!(isset($_SESSION["login"]) && $_SESSION["login"] == "OK")) 
    {
        header("Location: index.php");
        exit;
    }
    else
    {
        $id = $_GET['newsid'];
        $query = "DELETE FROM `Oglasi` WHERE `ID` = '$id'";
        header("Location: oglasi.php");
    }
?>  

Thank you in advanced!

user2940296

Add this before ' header("Location: oglasi.php"); ' -

mysql_query($query);

You need to perform the query against the database and mysql_query() does that.

So, your code becomes-

<?php
session_start();
require('konektor.php');

if(!(isset($_SESSION["login"]) && $_SESSION["login"] == "OK")) 
{
    header("Location: index.php");
    exit;
}
else
{
    $id = $_GET['newsid'];
    $query = "DELETE FROM `Oglasi` WHERE `ID` = '$id'";
    mysql_query($query);
    header("Location: oglasi.php");
}
?> 

Just to check that the query has been executed right there, you can also do this-

    <?php
session_start();
require('konektor.php');

if(!(isset($_SESSION["login"]) && $_SESSION["login"] == "OK")) 
{
    header("Location: index.php");
    exit;
}
else
{
    $id = $_GET['newsid'];
    $query = "DELETE FROM `Oglasi` WHERE `ID` = '$id'";
    $result = mysql_query($query);
    if(!$result) 
    {
        die("Could not archive" . mysql_error());
        //This will display any error in the execution of query.
    } 
    header("Location: oglasi.php");
}
?> 

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

"On Delete Cascade" if deleting a row from the child table

From Dev

Deleting Row from users table PHP MYSQL

From Dev

Deleting a row from an HTML table in javascript

From Dev

AJAX/Jquery not deleting row from MySQL table

From Dev

Deleting row in Sqlite table

From Dev

deleting a row in a table

From Dev

In Angularjs, how to update table data after deleting a row from it

From Dev

Deleting specific row from a table in MySQL using PHP

From Dev

How to get the value of a cell from an html table after deleting the row?

From Dev

Deleting table row by id with jQuery

From Dev

Deleting Row in table using jQuery

From Dev

UITableView deleting row reduced table row height

From Dev

Safely deleting a row from a matrix

From Dev

Deleting a Row from JQuery Datatables

From Dev

Deleting Row from Gridview with SelectedIndexChanged

From Dev

Android Deleting Row from SQLITE

From Dev

Safely deleting a row from a matrix

From Dev

Android deleting a row from a DB

From Dev

Android Deleting Row from SQLITE

From Dev

User deleting a row from a JTable

From Dev

Row not deleting from SQLite Database

From Dev

Deleting SQL datarow from a table swipes position of first and second row in vb.net

From Dev

Deleting row in table with Jquery in mvc project

From Dev

404 Error When Deleting Table Row in Azure

From Dev

Deleting rows and insert row in pivot table laravel

From Dev

Deleting a Row in a rowReorder Table Resets Reordering

From Dev

Always deleting last row of table in MVC View

From Dev

Deleting row in table with Jquery in mvc project

From Dev

renumber appended table row in javascript after deleting

Related Related

HotTag

Archive