Solved

Passing a variable value to query string using a hidden field

Posted on 2008-06-13
7
1,487 Views
Last Modified: 2013-12-13
I have a variable name $vars where I am saving all the variables such as:
if($publish_year) $vars .= "&year=".$publish_year;

and then passing it through a form as following:
<input id="vars" name="vars" value="<? echo $vars; ?>" type="hidden" />
<label for="perPage">Number</label>
          <select id="perPage" name="perPage">
            <option value="10"<? if($_GET['perPage'] == '10'){ ?> selected="selected"<? } ?>>10</option>
            <option value="25"<? if($_GET['perPage'] == '25'){ ?> selected="selected"<? } ?>>25</option>
            <option value="50"<? if($_GET['perPage'] == '50'){ ?> selected="selected"<? } ?>>50</option>  
            <option value="100"<? if($_GET['perPage'] == '100'){ ?> selected="selected"<? } ?>>100</option>
          </select>


The output in the query string shows all % % why is that?
here's the output

www.mytestwebsite.php?order_by=Date+DESC&vars=%26year%3D2000&perPage=25
Technicall I should have year=2000

any ideas?
thanks

0
Comment
Question by:martyje
  • 4
  • 3
7 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
You are looking at URL-encoded strings when you see those % signs
0
 

Author Comment

by:martyje
Comment Utility
How do I get rid of them?
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Good question!  Something is "helping" you by url-encoding things in your form.  Hex 26 is an ampersand and hex 3D is an equal sign.  If you can post the PHP that generates the link, I may be able to pick up the point.  Or you can look at the PHP function urldecode() and it may be just what you need once you get the hidden string back into your script.  ~Ray
0
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

Author Comment

by:martyje
Comment Utility
This is how I resolved the issue:

$body = ereg_replace("\n|<p>|</p>", "%0A", "Title: ". $title. "</p><p>". "Published Date: ". $publish_date. "
                                      </p>");
$contact_email=  "<a href=\"mailto:$contact_data?subject=Test%20Email&amp;body=$body\">$contact_data</a>";
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
Just wondering, did you try the urldecode() function?
0
 

Author Comment

by:martyje
Comment Utility
Yes I did. That didn't work.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 250 total points
Comment Utility
Hmm.  It worked perfectly for me.  Here is the script I used to test it before posting the answer.

You can run that script here:
http://www.laprbass.com/RAY_urldecode.php

I copied your example with cut-and-paste, ran it through urldecode() and got this output, which is correct:
www.mytestwebsite.php?order_by=Date DESC&vars=&year=2000&perPage=25

Can you please post the output from your test that didn't work?
<?php
 

if ($_GET["q"] == "d") {

  $script  = $_SERVER["SCRIPT_FILENAME"];

  $string = file_get_contents($script);

  header("Content-type: text/plain");

  header("Content-disposition: attachment; filename=\"" . $script . "\";" );

  echo $string;

  flush();

} else {

  echo "<br /><strong>Here is the output of urldecode()</strong>\n";

  echo "<br />\n";

  echo urldecode("www.mytestwebsite.php?order_by=Date+DESC&vars=%26year%3D2000&perPage=25");

  echo "<br /><br /><a href=\"$PHP_SELF?q=d\">To download the contents of this script, click here</a>\n";

}

die();

?>

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
php mail headers 2 8
Responsive Design Tools 6 36
PHP Startup Error 12 29
how to us ob_start in a function 11 33
Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now