PHP $GET如果错误的表单号


PHP $GET If Wrong Form No

我对PHP $GET有疑问。我有一个编辑链接,像这样:

<a href="edit.php?form_no=<?php echo $form_no; ?>"

单击后,它将重定向到显示基于表单号的数据的详细信息页面。

<?php
$form_no = $_GET['form_no'];
if wrong get form no
{
}
?>

现在我面临的问题,如果我输入url网址错误的形式没有。我想做的是重定向到另一个页面,如果用户输入错误的表单号

任何建议吗?

需要设置一个条件表单id是否存在于数据库中,如果不存在则重定向对于

//Query
$id_to_edit = $_GET['id']; 
/* Don't forget to sanitize, i.e is your id only numeric, no html in the id etc */
$fetch_ids = mysqli_query($connection, "SELECT id FROM tbl_name WHERE id = $id_to_edit");
if(mysqli_num_rows($fetch_ids) == 0) { //Check, if no rows are returned so redirect
   header('Location: whatever.php');
   exit;
}

你也可以抛出Id不存在的错误,通过在重定向之前设置会话,在重定向页面上抛出错误,然后取消会话变量