How to send multiple values in a href link in PHP?

前端 未结 2 1902
一个人的身影
一个人的身影 2020-12-20 03:44

I want to send multiple values to a different page using a href link. But what I retrieve is the first 2 values only, rest shows an error of undefined index.

相关标签:
2条回答
  • 2020-12-20 04:17

    You must HTML-escape those ampersands properly:

    ?coice=search&cat=...&subcat=...&srch=...
    

    &sub (of &subcat) gets interpreted as ⊂ which is a special HTML entity for the subset operator:

    ⊂ or ⊂ = subset of ⊂
    

    Also make sure you properly escape your variables to prevent XSS.

    0 讨论(0)
  • 2020-12-20 04:20

    try using urlencode, as if there are any special characters in the strings, it could have an effect on the querystring as a whole;

    echo "<a href='index.php?choice=search&cat=".urlencode($cat)."&subcat=".urlencode($subcat)."&srch=".urlencode($srch)."&page=".urlencode($next)."'> Next </a>";
    

    Plus you had a space between srch and page, that could have been causing a problem.

    0 讨论(0)
提交回复
热议问题