我正在尝试创建一个删除链接,当我点击它时会删除带有给定ID的sql表中的一行,它应该是这样的,但它不起作用,请你看一下我的代码并告诉我,我做错了什么,谢谢!
这就是链接,当我点击存档它应该删除该行。
+----+---------------------+---------------------+----------------------+------------------------+
| | A | B | C | D |
+----+---------------------+---------------------+----------------------+------------------------+
| 1 | Age | Sex | Race | Height |
| 2 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 3 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 4 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 5 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 6 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 7 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 8 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 9 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 10 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 11 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 12 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 13 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 14 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 15 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 16 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 17 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 18 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 19 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 20 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
| 21 | [dropdown of myAge] | [dropdown of mySex] | [dropdown of myRace] | [dropdown of myHeight] |
+----+---------------------+---------------------+----------------------+------------------------+
这是archivenews.php
echo '<td><a href="archivenews.php?newsid='. $row['ID'] .'">Arhiviraj</a>/<a href="archivenews.php?newsid='. $row['ID'] .'">Obrisi</a></td>';
先谢谢你了!
答案 0 :(得分:0)
在'header(“Location:oglasi.php”)之前添加; ' -
mysql_query($query);
您需要对数据库执行查询,mysql_query()会执行此操作。
所以,你的代码变成了 -
<?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");
}
?>
只是检查查询是否已在那里执行,您也可以执行此操作 -
<?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");
}
?>