在PHP中验证用于从多维数组检索值的表单数据
在使用form.php从process.php上的$laws数组检索特定文章之前,我想知道如何验证form.php中的数据在PHP中验证用于从多维数组检索值的表单数据,php,Php,在使用form.php从process.php上的$laws数组检索特定文章之前,我想知道如何验证form.php中的数据 <?php session_start(); $laws=array( "group1"=>array( "1"=>array( "1"=>"This is article (1) in chapter (1) of (group
<?php
session_start();
$laws=array(
"group1"=>array(
"1"=>array(
"1"=>"This is article (1) in chapter (1) of (group1)",
"2"=>"This is article (2) in chapter (1) of (group1)",
"3"=>"This is article (3) in chapter (1) of (group1)",
),
"2"=>array(
"1"=>"This is article (1) in chapter (2) of (group1)",
"2"=>"This is article (2) in chapter (2) of (group1)",
"3"=>"This is article (3) in chapter (2) of (group1)",
),
),
"group2"=>array(
"1"=>array(
"1"=>"This is article (1) in chapter (1) of (group2)",
"2"=>"This is article (2) in chapter (1) of (group2)",
"3"=>"This is article (3) in chapter (1) of (group2)",
),
"2"=>array(
"1"=>"This is article (1) in chapter (2) of (group2)",
"2"=>"This is article (2) in chapter (2) of (group2)",
"3"=>"This is article (3) in chapter (2) of (group2)",
),
)
);
$_SESSION['group'] = $_GET['group'];
$_SESSION['chapter'] = $_GET['chapter'];
$_SESSION['article'] = $_GET['article'];
$group = $_SESSION['group'];
$chapter = $_SESSION['chapter'];
$article = $_SESSION['article'];
// Echo Article from Laws Array
echo $group . " chapter" . $chapter . " article" . $article . "<br/>";
echo $laws[$group][$chapter][$article];
?>
<br/>
<a href="sample.php">PREVIOUS Articles</a> <a href="sample.php">NEXT Articles</a>
(form.php)
问题2
我应该在下一篇文章和上一篇文章的链接中添加什么PHP代码,以便在当前回送的文章之后回送下一篇文章
如何将此代码添加到链接中
由于下一篇文章和上一篇文章链接不再访问特定章节中不存在的数组以防止错误被回显,因此在回显上一篇文章或第一篇文章时,应如何处理页面
谢谢大家! 问题1:
你试过intval吗?
所以,按照你想要的顺序进行
if(isset($_GET['group']) && !empty($_GET['group']) && is_int($_GET['group'])){
$groupval = intval($_GET['group']);
$_SESSION['group'] = ($groupval > 0)? $groupval : 1; //A group cannot be 0
}
您也可以在章节和文章中使用类似的语句
问题2:
您只需使用返回给您的get值,加1和减1。
例如:
echo'
请注意,如果这是最后一篇文章,您必须进行检查,然后继续下一组/接下来的任何内容
Data in CHAPTER and ARTICLE input forms:
are not empty;
are numbers;
are not less than or greater than the existing array Chapters and Article numbers;
do not have spaces;
do not have decimals;
do not have letters;
do not have negative, positive and; or other signs;
if(isset($_GET['group']) && !empty($_GET['group']) && is_int($_GET['group'])){
$groupval = intval($_GET['group']);
$_SESSION['group'] = ($groupval > 0)? $groupval : 1; //A group cannot be 0
}