PHP $ _GET变量导致问题

时间:2016-04-15 23:16:34

标签: php get

我在表中有一个链接,其ID传递给另一个页面

admin_shifts.php

<a href=admin_shifts_view.php?id=1>view</a>

我在第二页中获取此值并使用它从sql数据

创建表

admin_shifts_view.php

$shifts_id = $_GET['id']

我点击一个按钮删除那个转移到我...

<a href=delete_from_shift.php?userid=" . $user_id ."&shiftid=" .$shift_id.">Remove</a>

delete_from_shift.php

if(isset($_GET['userid'])){

$user_id = $_GET['userid'];
$shifts_id = $_GET['shiftid'];

$delete_sql = "DELETE FROM user_shifts WHERE user_id=" . $user_id . " AND shifts_id=" .$shifts_id;
$delete_result = $database->query($delete_sql);

$deleted = "<div class='alert alert-success' role='alert'>Employee successfully removed</div>";

}else{

$deleted = "<div class='alert alert-danger' role='alert'>Problem removing employee at this time</div>";

}

$_SESSION['delete_user'] = $deleted; 
header("location:admin_shifts_view.php");

因此,当我重定向到admin_shifts_view.php时,我收到一个未定义的索引错误。有什么建议吗?

1 个答案:

答案 0 :(得分:3)

只需在header()

中再次打开参数
header("location:admin_shifts_view.php?id=$user_id");