PHP$GET如果表单错误,则返回否
我对PHP$GET有疑问。我有这样一个编辑链接:PHP$GET如果表单错误,则返回否,php,Php,我对PHP$GET有疑问。我有这样一个编辑链接: <a href="edit.php?form_no=<?php echo $form_no; ?>" 现在我面临的问题是,若我键入错误的url网址表单号。若用户键入错误的表单号,我想做的是重定向到另一个页面 有什么建议吗?所以您需要有一个条件,即该表单id是否存在于数据库中,如果没有,则需要重定向以便查询 //Query $id_to_edit = $_GET['id']; /* Don't forget to san
<a href="edit.php?form_no=<?php echo $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不存在的错误,方法是在重定向之前设置会话,在重定向页面上抛出错误,然后取消设置会话var,您的问题是什么?你在哪里这么做?你所说的错误表格no是什么意思?一旦从post中检索到表单号,就可以使用条件(例如-if($form\u no>10){})重定向到另一个页面。重定向可以通过“header('Location:'.$url)”完成。如果用户键入错误的表单编号,我想做的是重定向到另一个页面。您的问题是“如何重定向”或“如何确定表单编号是否错误”<代码>如果($form_no!=)标题('Location:*您希望表单去的地方*)代码>
//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;
}