Jump to content

passing more than one variable through URL


breaststroke

Recommended Posts

Hello!I have a little question I hope somebody can help me.I am not sure whether I have to post on PHP or on XHTML. Sorry if I am doing wrong.I am trying to validate my html code which includes php.Every time I try to pass more than one variable onto another page, through URL, I get errors.This is what I do:I add a link like this: <a href="secondpage.php?variable1=$variable1&variable2=$variable2">Go</a>But it always says, second and third,etc..variables are not defined.I doesn´t depend on the variables. I always defined them before the link. And it always accept the first one.Should I change my script to another one?Thank you very much in advance.Regards

Link to comment
Share on other sites

i think showing code will be better to point out where the problem occuring.

Link to comment
Share on other sites

i think showing code will be better to point out where the problem occuring.
This is the kind of link I am using:
 .. <div> <a style="color:gray"  href='visitprofile.php?a=$cochea&codigo2=$codigo2&b=$cocheb&c=$cochec'>Visit</a></div> .. 

I thought it was the normal way to passs variables through URL( I don´t know another). Nothing changes if I exchange the position of the variables. Always the first one doesn´t give an error, but the next ones do. It doesn´t depend, either, on the value of the variables. I use that on several pages, not always with the same variables. Thank you Regards

Link to comment
Share on other sites

<a style="color:gray" href='visitprofile.php?a=$cochea&codigo2=$codigo2&b=$cocheb&c=$cochec'>Visit</a></div>

if you're trying to mix PHP and HTML like that it's not going to work. PHP is processed before the HTML but only within <?php ?> tags. This is how you would want to do something like that.

<?php$var1 = 1;$var2 = 2;$var3 = 3;$baseUrl = 'visitprofile.php';$fullUrl = $baseUrl + '?a=' + $var1 + '&b=' + $var2 + '&c=' + $var3;?><html><body>...<div>   <a href=' <?php echo urlencode($fullUrl) ?> '>Visit</a></div>..</body></html>

there are certainly shorter ways of doing that, but for explanations sake and as an illustrative device, it should make the concept a bit clearer on initial read. Feel free to modify/shorten/de-verbose it if you like :)

Link to comment
Share on other sites

<a style="color:gray" href='visitprofile.php?a=$cochea&codigo2=$codigo2&b=$cocheb&c=$cochec'>Visit</a></div>

if you're trying to mix PHP and HTML like that it's not going to work. PHP is processed before the HTML but only within <?php ?> tags. This is how you would want to do something like that.

<?php$var1 = 1;$var2 = 2;$var3 = 3;$baseUrl = 'visitprofile.php';$fullUrl = $baseUrl + '?a=' + $var1 + '&b=' + $var2 + '&c=' + $var3;?><html><body>...<div>   <a href=' <?php echo urlencode($fullUrl) ?> '>Visit</a></div>..</body></html>

there are certainly shorter ways of doing that, but for explanations sake and as an illustrative device, it should make the concept a bit clearer on initial read. Feel free to modify/shorten/de-verbose it if you like :)

´hello again,thank you , the scientist, for your reply.I am quite new at programming and I don´t know many ways to do the same thing.( Normally only one, or less..:)).And sorry because I am not sure I explained myself correctly. ( and English is not my native language).The script I put here, which I am using on my pages, does work.The script( as I am using it)is within <?php and ?> tags on my pages (I didn´t include them here) .I have everything between html tags and in this case also within the tags above mentioned. Even when I define the variables that I include into the link.So, sorry, I don´t know if it seemed like the link I am using is not within php tags.So it works and I can get the variables on the other page(with GET).The problem for me is just when it comes to validate html code, because I get those errors.Should I use the way you have showed(urlencode, etc..)or similar to pass more than one variable?(it looks so different from the one I am using)If so I don´t know how I could pick them on the other page.Thank you very much again,regards
Link to comment
Share on other sites

php has a urldecode function as well.I guess it would be more helpful if you stated the nature of the validation errors. (if urldecode doesn't solve the problem) Does urlencode solve the validation problem?edit: also, along with the validation error, can you include the exact HTML output (from view source) of the line/code in question?

Link to comment
Share on other sites

php has a urldecode function as well.I guess it would be more helpful if you stated the nature of the validation errors. (if urldecode doesn't solve the problem) Does urlencode solve the validation problem?edit: also, along with the validation error, can you include the exact HTML output (from view source) of the line/code in question?
hi,I have tried with urlencode but it didn´t work. The errors dissapeared but the links didn´t work.I am not very sure about the following part:
<?php$var1 = 1; //this$var2 = 2; //this$var3 = 3; //this$baseUrl = 'visitprofile.php';$fullUrl = $baseUrl + '?a=' + $var1 + '&b=' + $var2 + '&c=' + $var3;?>

I may haven´t used this function correctly, since I am not sure about those values(1,2,3). In anycase, I did it like that. This is what I get, regarding validation errors:

<a href='page2.php?coche1=$coche1&coche2=$coche2&coche3=$coche3'>page2</a>

line 80:column...---cannot generate system identifier for general entity "coche2"column... ---general entity "coche2" not defined and no default entitycolumn... ---reference to entity "coche2" for which no system identifier could be generatedcolumn...---entity was defined hereSorry, I tried to copy it but I couldn´t. I think th efirst column corresponds to where "=" is stated, next one th esame, third one where "coche2" is , and last one where "&" is.The following variables give the same errors. An as I said, no matter if I exchange them, the first one is always "accepted", and only that one. Regards

Link to comment
Share on other sites

i am assuming (cant see your code still)... you are writing the <a> tag outside the <?php ?> block.and variables (eg. $coche1) will evaluates the value only inside the php block.either echoing the <a> inside php block something like

<?php$value=0;echo "<a href='somepage.php?var=$value'>go</a>?>

or...

<a href='somepage.php?var=<?php echo $value; ?>'>go</a>

....should work.

Link to comment
Share on other sites

Hi again,yes my link is placed like this:<html>..<?php...print<<<HERE <a href='page.php?coche1=$coche1&.....'>page2</a>..HERE;?>..</html>and I have tried with &amp, but I am not sure if I am doing right:<a href='page.php?coche1=$coche1&ampcoche2=$coche2...,but now it is considering ampcoche2 as an entity(when validating). It says the same as before but about "ampcoche2"... instead of "coche2"....thank you, regards

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...