7, September 2008

postcode check script - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  Access_user Class (Moderator: Olaf)
Topic: postcode check script
« previous next »
Pages: [1] Print

Author Topic: postcode check script  (Read 1236 times)
Bill Cosby is my Father
*
Gender: Male
Posts: 4
28 credits
Members referred : 0


Try try again !


« on: Jul 29, 2007, 02:54:05 AM »

Olaf, please review this.  I wanted a scipt to check the validity of the post code entered.(So only valid codes fill my database).  I wanted to give a little back to help someone else save the time I spent.  Cheers!  Smiley

This is what I came up with.  I added this to the ext_user_profile.php

The tables used can be downloaded @ http://www.sanisoft.com/phpziplocator.

Here is the simple code I added.  Appears to work fine so far, but please review.

 I added this to the extra_text: $extra_msg[4] = "Postcode is invalid!  Try again.";

Code:
function save_profile_date($ident = "", $lang = "", $address = "", $pc = "", $city = "", $country = "", $phone = "", $fax = "", $hp = "", $notes = "", $field1 = "", $field2 = "", $field3 = "", $field4 = ""){
   //zip code check here....
    $work = mysql_query("SELECT * FROM zipdata where zipcode = '$pc' ") or die (mysql_error());
    $result = mysql_fetch_array($work);
    if ($result['zipcode'] != $pc) {$this->the_msg = $this->extra_text(4);
    return;
    }
    else {
   {
    if (!empty($ident)) {
       $sql = sprintf("UPDATE %s SET language=%s, address=%s, postcode=%s, city=%s, country=%s, phone=%s, fax=%s, homepage=%s, notes=%s, %s=%s, %s=%s, %s=%s, %s=%s, user_info=NOW() WHERE id = %s AND users_id = %d",
        PROFILE_TABLE, $this->ins_string($lang), $this->ins_string($address), $this->ins_string($pc),
        $this->ins_string($city), $this->ins_string($country), $this->ins_string($phone), $this->ins_string($fax),
        $this->ins_string($hp), $this->ins_string($notes), TBL_USERFIELD_1, $this->ins_string($field1),
        TBL_USERFIELD_2, $this->ins_string($field2), TBL_USERFIELD_3, $this->ins_string($field3),
        TBL_USERFIELD_4, $this->ins_string($field4), $this->ins_string($ident, "int"), $_SESSION['user_id']);
    } else {
      $sql = sprintf("INSERT INTO %s (id, users_id, language, address, postcode, city, country, phone, fax, homepage, notes, %s, %s, %s, %s, last_change) VALUES (NULL, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW())",
        PROFILE_TABLE, TBL_USERFIELD_1, TBL_USERFIELD_2, TBL_USERFIELD_3,
        TBL_USERFIELD_4, $_SESSION['user_id'], $this->ins_string($lang), $this->ins_string($address),
        $this->ins_string($pc), $this->ins_string($city), $this->ins_string($country), $this->ins_string($phone),
        $this->ins_string($fax), $this->ins_string($hp), $this->ins_string($notes), $this->ins_string($field1),
        $this->ins_string($field2), $this->ins_string($field3), $this->ins_string($field4));
    } 
    if (mysql_query($sql) or die (mysql_error())) {
      $this->profile_id = (empty($_SESSION['is_rec'])) ? mysql_insert_id() : $ident;
      $this->the_msg = $this->extra_text(2);
    } else {
      $this->the_msg = $this->extra_text(3);
    }
  }  } }
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Jul 29, 2007, 11:16:24 AM »

hmm... nice, I know that the US zip code is 100% numeric, testing the value against a database is possible but is a test against a regular expression not faster (enough)?


Last blog : Is your website is down? Know before your visitors do!
Bill Cosby is my Father
*
Gender: Male
Posts: 4
28 credits
Members referred : 0


Try try again !


« Reply #2 on: Jul 29, 2007, 09:42:15 PM »

I think what your saying is use the regular expressions to check for the correct snytax of the postcode entered, when what I had in mind(which probably takes longer);  is to check the submitted value against a complete listing of all postal codes.

I want to ensure when a search is done later that all results are valid. Is this over kill and if so, can you reccommend a better method.

Cheers!
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: Jul 29, 2007, 11:08:04 PM »

but how do you protect your application about cheating entries? do you have second validation that the entered value belongs to the user?


Last blog : Is your website is down? Know before your visitors do!
Bill Cosby is my Father
*
Gender: Male
Posts: 4
28 credits
Members referred : 0


Try try again !


« Reply #4 on: Jul 29, 2007, 11:15:37 PM »

Fair enough, I was pretty tired last night and did not think of that immediately.  I will add the testing with the regular expressions before it is checked against the database for validity.

Embarrassed
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: Jul 30, 2007, 12:53:51 AM »

Fair enough, I was pretty tired last night and did not think of that immediately.  I will add the testing with the regular expressions before it is checked against the database for validity.

 Embarrassed

that will not help Sad

if you need to be 100% sure you need to match the postal code against the address/city


Last blog : Is your website is down? Know before your visitors do!
Bill Cosby is my Father
*
Gender: Male
Posts: 4
28 credits
Members referred : 0


Try try again !


« Reply #6 on: Jul 30, 2007, 01:31:07 AM »

I think I understand .  So take the postcode, and check against the address & city sumitted.  This may be more than what I need, but you answered my question on how make 100% sure it's valid. 

Thanks !
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6309
38674 credits
Members referred : 374


It's time to use PHP5!


« Reply #7 on: Jul 30, 2007, 08:05:16 AM »

I think I understand .  So take the postcode, and check against the address & city sumitted.  This may be more than what I need, but you answered my question on how make 100% sure it's valid. 

Thanks !

you're welcome, be sure that you only validate the data you really need. It makes no sense to validate the address from someone who has the chance to win $1mio if he enter his address Cheesy


Last blog : Is your website is down? Know before your visitors do!
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=6956
Tags : zipcode verification Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  Access_user Class (Moderator: Olaf)
Topic: postcode check script
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Sep 07, 2008, 09:42:43 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 36.301
Total Topics: 7.479
Total Members: 3.904
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: Brandon

29 Guests, 3 Users online :

11 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.