PHP初学者在线:)。 我有两个文件(viewKands.php-列表记录和izbrisi.php-用于删除数据库中的记录。我尝试从db(upisi)删除记录。但没有运气。 这是代码......我的错误在哪里?
viewKands.php:
$kon = mysqli_connect("localhost", "root", "", "upisi");
$kon->set_charset("utf8");
if (mysqli_connect_error()) {
echo "Greska pri konekcija so baza: " . mysql_error();
}
$sqlView = "SELECT idPrijava,brPrijava,jazik,struka,profil,imeKand,tatIme,"
. "prezKand from tblprijava ";
$result = mysqli_query($kon, $sqlView);
$rBr = 1;
while ($rowV = $result->fetch_assoc()) {
$id = $rowV["idPrijava"];
echo "<tr><td>" . $rBr . "</td><td>" . $rowV["brPrijava"] . "</td><td>" . $rowV["jazik"] . "</td><td>" . $rowV["struka"] .
"</td><td>" . $rowV["profil"] . "</td><td>" . $rowV["imeKand"] . " " . $rowV["tatIme"] . " " . $rowV["prezKand"] .
"</td><td><a href='uredi.php'>Уреди</a></td>" . " <td><a href='izbrisi.php?id=$id'>X</a></td>" . "</td></tr>";
$rBr++;
}
izbrisi.php(删除记录)
$delkon = mysqli_connect("localhost", "root","","upisi");
$delkon->set_charset("utf8");
if (isset($_GET["idPrijava"]) != "") {
$delete = $_GET["idPrijava"];
$dqry = "DELETE FROM tblprijava WHERE idPrijava='$delete'";
$delete = mysqli_query($delkon, $dqry);
if ($delkon->query($dqry) === TRUE) {
header("Location:viewKands.php");
} else {
echo mysqli_error($delete);
}
} else {
echo "ID error";
}
$delkon->close();
答案 0 :(得分:0)
将代码更改为 izbrisi.php
$delkon = mysqli_connect("localhost", "root","","upisi");
$delkon->set_charset("utf8");
if (isset($_GET["id"]) != "") {
$delete = $_GET["id"];
$dqry = "DELETE FROM tblprijava WHERE idPrijava='$delete'";
$delete = mysqli_query($delkon, $dqry);
if ($delkon->query($dqry) === TRUE) {
header("Location:viewKands.php");
} else {
echo mysqli_error($delete);
}
} else {
echo "ID error";
}
$delkon->close();