Reputation: 11676
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.
My code is:
<?php
echo "<a href='index.php?choice=search&cat=".$cat."&subcat=".$subcat."&srch=".$srch."&page=".$next."'> Next </a>";
?>
I get the values of "choice" and "cat" only. Please tell me whats wrong in the above code.
Upvotes: 1
Views: 42805
Reputation: 265251
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.
Upvotes: 3
Reputation: 4150
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.
Upvotes: 6