Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 10 of 10
  1. #1
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts

    $_GET variables from a url string

    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:

    www.domain.com/search/?keywords=keywords..etc...

    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.
    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Do you have a sample of your code that you have. It would make it easier to see what the problem is

  • #3
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts
    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...

    PHP Code:
    <?php

        
    //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
    Last edited by danielwarner; 01-03-2007 at 01:56 PM.
    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.

  • #4
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

    Sorry

  • #5
    teh Moderatorinator
    Join Date
    Sep 2004
    Location
    USA
    Posts
    2,472
    Thanks
    4
    Thanked 40 Times in 40 Posts
    What version of php are you using?

  • #6
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts
    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.

  • #7
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    like i said i think its a problem with your mod rewrite. if you do this

    Code:
    http://www.caravansandtrailertents.co.uk/index.php?pageref=search&manufacture=13
    then "13" is shown on the screen on its own and in the mysql_query

  • #8
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts
    do you have any suggestions in this case for how i can hide the url string containing the index.php?pageref....etc?
    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.

  • #9
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #10
    Regular Coder
    Join Date
    Oct 2005
    Location
    Surrey, England
    Posts
    286
    Thanks
    2
    Thanked 2 Times in 2 Posts
    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!
    Daniel Warner
    - - - - - - - - - -
    GuitarMart.co.uk - Free Online Classified Advertisement for Guitarists in the United Kingdom. Free Ads with a Free Photo.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •