ja_blackburn Posted December 13, 2010 Share Posted December 13, 2010 Hi I have a function that takes a postcode and splits it so i can enter into DB into two formats, full postcode and prefix. The function is: function check_form_postcode($postcode) { $postcode = strtoupper(str_replace(chr(32),'',$postcode)); $suffix = substr($postcode,-3,3); $prefix = substr($postcode,0,(strlen($postcode)-3)); if (preg_match('/(^[A-Z]{1,2}[0-9]{1,2}|^[A-Z]{1,2}[0-9]{1}[A-Z]{1})$/',$prefix) && preg_match('/^[0-9]{1}[ABD-HJLNP-UW-Z]{2}$/',$suffix)) { $postcode_syntax_check = 1; } else { $postcode_syntax_check = 0; } if($postcode_syntax_check){ $return = $prefix."::".$suffix; } return($return); } I POST the form data and in the top of the same page I get all of the form data and here is is where things go wrong: if ($b == 'go') { //Gets form data $main_event_name = my_import('main_event_name', 'P', 'TXT'); $main_event_type = my_import('main_event_type', 'P', 'TXT'); $main_event_date = my_import('main_event_date', 'P', 'TXT'); $main_event_city = my_import('main_event_city', 'P', 'TXT'); $postcode = my_import('postcode', 'P', 'TXT'); $main_event_added = my_import('main_event_added', 'P', 'INT'); $main_event_active = my_import('main_event_active', 'P', 'INT'); $postcode_array = check_form_postcode($postcode); $postcode = explode($postcode_array, "::"); $prefix = $postcode[0]; $fullpostcode = $postcode[0]." ".$postcode[1]; $valkey = md5(microtime()); $info = array( "main_event_name"=> $main_event_name, "main_event_type" => $main_event_type, "main_event_date" => $main_event_date, "main_event_city" => $main_event_city, "main_event_active" => $main_event_active, "main_event_added" => $sys['now'], "main_event_pcode" => $fullpostcode, "main_event_pcode_prefix" => $prefix, "eo_id" => $eo['id'] ); $table = $db['main_event']; $userid = my_insert($info, $table); When I enter into the DB all I get is the "::" no data. I know that the POST works as I can enter the data easily without the function going wrong. Thanks for any help, i am new to arrays go easy if I have made an obvious mistake! Cheers... Link to comment https://forums.phpfreaks.com/topic/221551-help-with-postcode-splitting-function-arrays/ Share on other sites More sharing options...
btherl Posted December 13, 2010 Share Posted December 13, 2010 What does check_form_postcode() return? Try calling it directly with known values, and then use var_dump on the result: $return = check_form_postcode("ABCDE"); var_dump($return); exit(); What should your code do if the postcode check fails? Also check the manual page for explode(): http://php.net/manual/en/function.explode.php . The arguments should be the other way around. Link to comment https://forums.phpfreaks.com/topic/221551-help-with-postcode-splitting-function-arrays/#findComment-1146860 Share on other sites More sharing options...
ja_blackburn Posted December 13, 2010 Author Share Posted December 13, 2010 Thanks. Are you saying that it should read like this: $postcode = explode("::", $postcode_array); I'm returning a 'NULL' btw Link to comment https://forums.phpfreaks.com/topic/221551-help-with-postcode-splitting-function-arrays/#findComment-1146879 Share on other sites More sharing options...
ja_blackburn Posted December 13, 2010 Author Share Posted December 13, 2010 Actually I have it working now, thanks for the pointer. J Link to comment https://forums.phpfreaks.com/topic/221551-help-with-postcode-splitting-function-arrays/#findComment-1146883 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.