PHP Help URL Encode

Associate
Joined
18 Oct 2002
Posts
100
Hi

I've setup a database of manufacturers to search for by a dropdown
When the value is selected hit the search button & brings back results etc

Manufacturers are stored as varchar in MYSQL

eg manufacturers are

BMW
Aston Martin
Volvo

When you select & search for BMW the results don't come back as
myurlt/search1.php?Manufacturer=BMW%22&Submit=Search

%22 seams to be a url encode issue & doesn't bring back any results

Should be
myurlt/search1.php?Manufacturer=BMW&Submit=Search

Now a 2 part name (i.e. Aston Martin) only picks up the first part
myurlt/search1.php?Manufacturer=ASTON&Submit=Search
but brings back the results ok but it would be nice to get it to enter as
ASTON+MARTIN

PHP:
<?php

function menu( $_nam ) 
    { 
    $_sel = '<form name="form" action="search1.php" method="get"><select name="'. $_nam .'">'; 
    $_sel .= '<option selected>Manufacturers</option>'; 
    $_qry = mysql_query("Select distinct Manufacturer From t21 Where Manufacturer > '120' Order By Manufacturer Asc"); 
		    while ($_dat = mysql_fetch_array( $_qry )) { 
        $_sel .='<option value='.strtoupper($_dat['Manufacturer']).'">'.strtoupper($_dat['Manufacturer']).'</option>' .""; 
    } 

    $_sel .= '</select><input type=Submit name=Submit value=Search onSubmit=value></form>'; 
			
    return($_sel); 
}  


 echo menu('Manufacturer'); 
 ?>

Anyone know where i'm going wrong?

Thanks in advance
 
%22 is a double quote (").

You haven't put quotes around your variable names except for in one case, which is why it's sending that double quote as part of the value.

Look carefully:

Wrong:
Code:
$_sel .='<option value='.strtoupper($_dat['Manufacturer']).'">'.strtoupper($_dat['Manufacturer']).'</option>' ."";
Right:
Code:
$_sel .='<option value='.strtoupper($_dat['Manufacturer']).'>'.strtoupper($_dat['Manufacturer']).'</option>';
:)

Edit: As for part two, use urlencode() around any values. So instead of value=[an uppercase version, which may fail due to case sensitivity anyway], you have.... value=[aha, a urlencoded web-friendly version].

Code:
$_sel .='<option value='.urlencode($_dat['Manufacturer']).'>'.strtoupper($_dat['Manufacturer']).'</option>';
 
Ok working now but I've changed the urlencode to urldecode as split words weren't working correctly Aston Martin became Aston%2BMartin instead of Aston+Martin

urldecode returns only the first part of the words Aston in the search

Code:
$_sel .='<option value='.urldecode($_dat['Manufacturer']).'>'.strtoupper($_dat['Manufacturer']).'</option>'; 
    }

I'm I missing something here?
 
Code:
<?php

function menu( $_nam ) 
    { 
    $_sel = '<form name="form" action="data_search.php" method="get"><select name="'. $_nam .'">'; 
    $_sel .= '<option selected>Search by Manufacturer</option>'; 
    $_qry = mysql_query("Select distinct Manufacturer From t21 Where Manufacturer > '120' Order By Manufacturer Asc"); 
		    while ($_dat = mysql_fetch_array( $_qry )) { 
      	
$_sel .='<option value='.urldecode($_dat['Manufacturer']).'>'.$_dat['Manufacturer'].'</option>'; 
    } 

    $_sel .= '</select><input type="Submit" name="Submit" value="Search" onclick="value"><input type="reset" value="Reset" name="reset"></form>'; 
			
    return($_sel); 
}  
 echo menu('Manufacturer'); 
 ?>
 
Beansprout,

I haven't made an input form as yet, only the dropdown

I've tried urlencode & the url changes to aston%2bmartin which is a + but doesn't find any results

urldecode changes to aston (without martin) but does bring back results for aston but isn't accurate
 
Last edited:
Back
Top Bottom