View Full Version : $_GET variables from a url string

01-03-2007, 01:36 PM
im using a set of GET's form a url string that is generated from a search form. The problem is that none of the variables are showing up when echoed. The variables are obviously there because they are held in the url.

The problem i think i may have broken it down to is that the string looks a little something like this:


do i need to include the file name in order for the $_GET to work? I did a test with this and worked better than without the file name but that may have been because it was a different file. Is there a way of doing this using $_GET variables?

I flicked through the idea of sessions but i decided that i much prefer the idea of the url changing per search, this way the user can copy the search result url into an email etc...

Thanks for your help.

01-03-2007, 02:39 PM
Do you have a sample of your code that you have. It would make it easier to see what the problem is

01-03-2007, 02:54 PM
ok well this is a very bad example. I know the query doesnt work or anything yet and the code is scrappy but thats because im only trying to build the query at the moment...


//Return Query Builder
$manufacture_query = $_GET['manufacture'];
$berth_query = $_GET['berth'];
$location_query = $_GET['location'];
$keywords_query = $_GET['keywords'];
$from_query = $_GET['from'];
$to_query = $_GET['to'];
$private_query = $_GET['private'];
$trade_query = $_GET['trade'];
$year_query = $_GET['year'];
$man_id2 = $manufacture_query;

if($from_query != ""){$search_returned = 1;}

if($_GET["manufacture"] == "0"){$manufacture_query = "";}
if($_GET["location"] == "0"){$location_query = "";}
if($_GET["year"] == "0"){$year_query = "";}
if($_GET["berth"] == "0"){$berth_query = "";}

//Attempting to echo results
echo $manufacture_query . "<br>" .
$berth_query . "<br>" .
$location_query . "<br>" .
$keywords_query . "<br>" .
$from_query . "<br>" .
$to_query . "<br>" .
$private_query . "<br>" .
$trade_query . "<br>" .
$year_query . "<br>";

if($search_returned = 1){
$result = "SELECT * FROM `adverts` WHERE `manufacture_id` ='$manufacture_query' && location_id ='$location_query' ORDER BY `timestamp` DESC";
echo $result;
else { $result = "SELECT * FROM `adverts` ORDER BY `timestamp` DESC"; }
Im pretty sure there is nothing wrong with the way i attempt to echo the variables...i did a var_dump and the result came back NULL so the $_GET doesnt want to collect the data from the url.

Heres a (not) working example. http://www.caravansandtrailertents.co.uk/search/ The page should show the query trying to be built for development purposes and it should try to echo the variable...thats why the code shows a series of <br>'s with no information.

The reason i dont want to use search/index.php is because caravansandtrailertents.co.uk/search/ is a mod_rewrite in my .htdocs for the url ...co.uk/index.php?pageref=search

01-03-2007, 03:19 PM
I think this may be a problem with the mod rewrite. but i have never done mod rewrite so i can't say for sure.


01-03-2007, 03:48 PM
What version of php are you using?

01-03-2007, 03:53 PM

01-03-2007, 04:02 PM
like i said i think its a problem with your mod rewrite. if you do this


then "13" is shown on the screen on its own and in the mysql_query

01-03-2007, 04:05 PM
do you have any suggestions in this case for how i can hide the url string containing the index.php?pageref....etc?

01-03-2007, 04:14 PM
why do you need to pass the search details in the url. can't you make the form a post form (method="post") and change $_GET[" to $_POST["

if you can't then this link http://www.phpfreaks.com/tutorials/23/1.php might help with the mod_rewrite

01-03-2007, 05:15 PM
Wow thanks for that tutorial, im working on converting it but by reading it i have realised that i have made a huge mistake in my .htaccess file and can improve the effeciency LOADS!

Thanks again!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum