我在代碼中發現了一個問題,當我想從數據庫中刪除用戶時,它必須刪除他,刪除代碼完美,但事後if條件顯示用戶已被刪除,我有一個後退按鈕,我點擊它,它應該重定向我回到教室與其他用戶在其中。課堂是由ID標識的,當然,但是當我點擊後退,就說明我沒有教室一類的ID ......所以它不是讓ID ...當點擊後退按鈕時,不從檢索器url中檢索id
// get value of id that sent from address bar
$id_student=$_GET['id_student'];
$id_trieda = $_GET['id_triedy'];
// Delete data in mysql from row that has this id
$zmaz='DELETE FROM $tbl_name WHERE id_student="'.$id_student.'" AND id_triedy="'.$id_trieda.'"';
mysqli_real_escape_string($prip, $zmaz);
$row = mysqli_query($prip,$zmaz);
// if successfully deleted
if($row){
echo "Študent bol úspešne vymazaný.";
echo "</br>";
echo "<a href='./trieda.php?id_triedy=".$_GET['id_triedy']."'>Späť do triedy<a/>";
}
else {
echo "Chyba";
}
?>
編輯:
// get value of id that sent from address bar
$id_student=$_GET['id_student'];
// Delete data in mysql from row that has this id
$zmaz="DELETE FROM $tbl_name WHERE id_student='$id_student'";
$result=mysql_query($zmaz);
// if successfully deleted
if($result){
$id_trieda = $_GET['id_triedy'];
echo "Študent bol úspešne vymazaný.";
echo "</br>";
echo "<a href='./trieda.php?id_triedy=".$id_trieda."'>Späť do triedy<a/>";
}
else {
echo "Chyba";
}
這裏是編輯的代碼,這是類似的工作,當我添加一個學生到類中,然後再次有一個後退按鈕,但它的工作....所以問題將刪除學生,它無法找到他在課堂上的ID是..我想..但我不知道如何得到這個課程的ID,然後他被刪除..
在您的Back鏈接中,嘗試使用'$ id_trieda'而不是'$ _GET ['id_triedy']'。 – ElendilTheTall
請參閱下面的回答 – ElendilTheTall