我想使用href
链接将多个值发送到不同的页面。但我检索到的只是前 2 个值,其余显示未定义索引的错误。
我的代码是:
<?php
echo "<a href='index.php?choice=search&cat=".$cat."&subcat=".$subcat."&srch=".$srch."&page=".$next."'> Next </a>";
?>
我只得到“选择”和“猫”的值。请告诉我上面的代码有什么问题。
我想使用href
链接将多个值发送到不同的页面。但我检索到的只是前 2 个值,其余显示未定义索引的错误。
我的代码是:
<?php
echo "<a href='index.php?choice=search&cat=".$cat."&subcat=".$subcat."&srch=".$srch."&page=".$next."'> Next </a>";
?>
我只得到“选择”和“猫”的值。请告诉我上面的代码有什么问题。
尝试使用urlencode,好像字符串中有任何特殊字符,它可能会对整个查询字符串产生影响;
echo "<a href='index.php?choice=search&cat=".urlencode($cat)."&subcat=".urlencode($subcat)."&srch=".urlencode($srch)."&page=".urlencode($next)."'> Next </a>";
另外,您在 srch 和 page 之间有一个空格,这可能会导致问题。
您必须正确地对这些 & 符号进行 HTML 转义:
?coice=search&cat=...&subcat=...&srch=...
&sub
(of &subcat
) 被解释为⊂
子集运算符的特殊 HTML 实体:
⊂ or ⊂ = subset of ⊂
还要确保正确转义变量以防止 XSS。