Jump to content
Larry Ullman's Book Forums

Problem With Postcode In Database


Recommended Posts

hello,

 

I made the second draft of the book, but I was a little mistake to be solved. I have a problem with the postal code, after completing the contact form on the site, the database I get a bad zip code, when I type in a ZIP code sample form 21-150 (in Poland we have a code of 5 digits) in the database shows me 00000. I'm Polish and I had to change the code included with the book. What can be wrong? please help.

 

checkout.php:

 

if (preg_match ('/^(^\d{2}-\d{3})$/', $_POST['zip'])) {

$z = $_POST['zip'];

} else {

$shipping_errors['zip'] = 'Podaj kod pocztowy!';

}

 

billing.php

 

if (preg_match ('/^(^\d{2}-\d{3})$/', $_POST['cc_zip'])) {

$cc_zip = $_POST['cc_zip'];

} else {

$billing_errors['cc_zip'] = 'Wpisz kod pocztowy!';

}

 

 

 

TABLE `customers` in Mysql

 

`id` int(10) unsigned NOT NULL AUTO_INCREMENT,

`email` varchar(80) NOT NULL,

`first_name` varchar(20) NOT NULL,

`last_name` varchar(40) NOT NULL,

`address1` varchar(80) NOT NULL,

`address2` varchar(80) DEFAULT NULL,

`city` varchar(60) NOT NULL,

`state` char(2) NOT NULL,

`zip` mediumint(5) unsigned zerofill NOT NULL,

`phone` int(10) NOT NULL,

`date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,

PRIMARY KEY (`id`),

KEY `email` (`email`)

) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;

Link to comment
Share on other sites

If you are trying to store the zip code as 21-150, the zip field in your table needs to be of a different type, at the moment it is set to mediumint and therefore is expecting all numbers. You will either need to convert $_POST['zip'] to all numerics or change the zip field in your table to varchar(6).

 

Why do you have auto_increment=4 at the end of the table?

  • Upvote 1
Link to comment
Share on other sites

That auto_increment=4 is from a database dump of the table.

 

If you're using Polish postal codes, the distance calculations won't work at all. Not unless you've got a database that maps latitude and longitude to Polish post codes.

  • Upvote 1
Link to comment
Share on other sites

Thank you for your help. In code I deleted my -, and changed the TABLE `customers` `zip` mediumint(5) unsigned zerofill NOT NULL on `zip` int(5) unsigned zerofill NOT NULL. I'm getting to the base of zip code 21150 in the format, and I'm happy with this solution.

 

Regards

Link to comment
Share on other sites

 Share

×
×
  • Create New...