postcode finder

This is a discussion on "postcode finder" within the PHP Forum section. This forum, and the thread "postcode finder are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 7th, 2008, 10:57
Reputable Member
Join Date: Dec 2005
Location: scotland
Age: 27
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
postcode finder

Trying to setup a simple postcode search in a site.

Basically, I want the user to enter their postcode into a form which then will check to see if that area is available.

Eg:

User enters : fa21 2e3


I want to check if the fa21 matchesa list of postcode which range from fa1 to fa39.

How is this possible? thanks
Reply With Quote

  #2 (permalink)  
Old Feb 7th, 2008, 13:52
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: postcode finder

Form:
HTML: Select all
<form action="handle.php">
<input type="text" name="postcode" />
<input type="submit" />
</form>
PHP: Select all

$pcode $_REQUEST['postcode'];
$validpcodes = array('np23 nf3''nog2 0od'); // add more valid postcodes
if(in_array($pcode$validpcodes)) 
{
// is valid

else 
{
//not valid

Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #3 (permalink)  
Old Feb 7th, 2008, 14:26
Daniel's Avatar
Elite Veteran
Join Date: Sep 2006
Location: The Kingdom of Rabbits
Age: 21
Posts: 2,051
Blog Entries: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Daniel
Re: postcode finder

How would that check if it was available?

You'd need a database and you'd want to get it to check against the database.
Last Blog Entry: Assassin's Creed (Nov 22nd, 2007)
Reply With Quote
  #4 (permalink)  
Old Feb 7th, 2008, 15:49
Reputable Member
Join Date: Dec 2005
Location: scotland
Age: 27
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Re: postcode finder

i have got a databse with lots of postcode, however how do i query on a few?

thanks guys
Reply With Quote
  #5 (permalink)  
Old Feb 7th, 2008, 16:02
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: postcode finder

PHP: Select all

$validpcodes = array();
//connect to db
$result mysql_query("SELECT postcode FROM postcodetable");
while(
$arr mysql_fetch_assoc($result))

$validpcodes[] = $arr['postcode'];

Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #6 (permalink)  
Old Feb 7th, 2008, 18:19
Reputable Member
Join Date: Dec 2005
Location: scotland
Age: 27
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Re: postcode finder

ok so i've got this far, but i must be mixing up the variable, can some tell me what i'm doing wrong
PHP: Select all

<?php

    
$validpcodes 
= array();
//connect to db
function get_db_connection(){
      
//connection parameters
        
$db_host '???;
        $db_userid = '
???';
        $db_password = '
???';
        $db_default_database = '
??';
        
      //throw fatal error if couldn'
t connect to mysql
        
if (! @mysql_connect($db_host$db_userid$db_password) ){
            
trigger_error('get_db_connection(): mysql_connect failed - '.mysql_error(), E_USER_ERROR);
            echo(
'get_db_connection(): mysql_connect failed - '.mysql_error());
        }

      
//throw fatal error if couldn't select correct (DEFAULT) database
        
if (! @mysql_select_db($db_default_database) ){
            
trigger_error('get_db_connection(): mysql_select_db failed - '.mysql_error(), E_USER_ERROR);
            echo(
'get_db_connection(): mysql_select_db failed - '.mysql_error());
        }
    }
    
$result mysql_query("SELECT outcode FROM geg_postcode_table");
while(
$arr mysql_fetch_assoc($result))

$validpcodes[] = $arr['outcode'];

$pcode $_REQUEST['postcode'];
$pcode = array($arr); // add more valid postcodes
if(in_array($pcode$arr)) 
{
echo 
'yes';

else 
{
echo 
'no';
}
and getting these errors
Quote:
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in ....coverage.php on line 26

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in ...coverage.php on line 26

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in ..coverage.php on line 27

Warning: in_array() [function.in-array]: Wrong datatype for second argument in ...coverage.php on line 33
no

Last edited by alexgeek; Feb 27th, 2008 at 20:35.
Reply With Quote
  #7 (permalink)  
Old Feb 7th, 2008, 18:29
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,649
Thanks: 0
Thanked 8 Times in 8 Posts
Send a message via MSN to Marc Send a message via Skype™ to Marc
Re: postcode finder

PHP: Select all

 $db_host = ???; 

you need to close the '

like:

PHP: Select all

  $db_host '???'
Reply With Quote
  #8 (permalink)  
Old Feb 7th, 2008, 18:32
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: postcode finder

Also this:
PHP: Select all

$pcode $_REQUEST['postcode'];
$pcode = array($arr); // add more valid postcodes 
Should just be:
PHP: Select all

$pcode $_REQUEST['postcode']; 

Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #9 (permalink)  
Old Feb 7th, 2008, 19:00
Reputable Member
Join Date: Dec 2005
Location: scotland
Age: 27
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Re: postcode finder

1st prob was just a mistake when i was taking out my database pw, etc.

fixed the 2nd one but still no joy, thought it was a connection problem but tested database with another script and it worked fine

these lines seem to be throwing up the probs

Quote:
$result = mysql_query("SELECT outcode FROM geg_postcode_table");

while($arr = mysql_fetch_assoc($result))

if(in_array($pcode, $arr))
Reply With Quote
  #10 (permalink)  
Old Feb 7th, 2008, 19:08
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: postcode finder

Supposed to be:
PHP: Select all

if(in_array($pcode$validpcodes)) 

Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #11 (permalink)  
Old Feb 7th, 2008, 19:37
Reputable Member
Join Date: Dec 2005
Location: scotland
Age: 27
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Re: postcode finder

fixed the last 2 probs but still having truble connecting, really strange
Reply With Quote
  #12 (permalink)  
Old Feb 7th, 2008, 20:00
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: postcode finder

Post errors.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
  #13 (permalink)  
Old Feb 7th, 2008, 20:23
Reputable Member
Join Date: Dec 2005
Location: scotland
Age: 27
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Re: postcode finder

just foubd out that the database i was accessing was incomplete and have had to re-think (temp) my plans, tryin to ue your origional script alex but no matter what postcode i enter it always comes back saying no?
PHP: Select all

<?php

$pcode 
$_REQUEST['postcode'];
$validpcodes = array('G1''G11''G12''G13''G14''G15''G2''G20''G21''G22''G23''G3''G31''G32''G33''G34''G4''G40''G41''G42''G43''G44''G45''G46''G5''G51''G52''G53''G60''G61''G62''G63''G64''G65''G66''G67''G68''G69''G71''G72''G73''G74''G76''G77''G78''G81''G82''G83''G84', ); // add more valid postcodes
if(in_array($pcode$validpcodes)) 
{
// is valid
echo 'yes';

else 
{
//not valid
echo 'no';

?>
any idea why?
Reply With Quote
  #14 (permalink)  
Old Feb 8th, 2008, 19:10
Reputable Member
Join Date: Dec 2005
Location: scotland
Age: 27
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Re: postcode finder

sorted, was case sensitive!! doh, easy fix. cheers again Alex
Reply With Quote
  #15 (permalink)  
Old Feb 8th, 2008, 19:22
Marc's Avatar
Moderator

SuperMember
Join Date: Apr 2007
Location: Scotland, UK
Age: 15
Posts: 1,649
Thanks: 0
Thanked 8 Times in 8 Posts
Send a message via MSN to Marc Send a message via Skype™ to Marc
Re: postcode finder

Haha.. Yeah.. PHP is case-senSitIvE
Reply With Quote
  #16 (permalink)  
Old Feb 8th, 2008, 19:28
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: postcode finder

Glad you have that sorted
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
postcode and name search box geoffmuskett PHP Forum 4 Feb 27th, 2007 11:43
Postcode CSV ocean Web Page Design 3 Oct 11th, 2006 20:03


All times are GMT. The time now is 11:48.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43