Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

PHP programmer help please


Guest

Recommended Posts

/* test for CM & Co postcode */

if (substr($postcode,1,2) <> 'CM') {

$error = true;

echo 'System available to residents of Essex postcodes CM & CO only!';

 

$messageStack->add('create_account', ENTRY_POST_CODE_ERROR);

}

 

I have the above code to stop anyone living outside my district using our services, as we only deliver locally.

 

However, I would like to add another postcode district 'CO' but whenever I change the code I cannot get it to work, see below.

 

How should it look?

 

/* test for CM & Co postcode */

if (substr($postcode,1,2) <> 'CM' and substr($postcode,1,2) <> 'CO') {

$error = true;

echo 'System available to residents of Essex postcodes CM & CO only!';

 

$messageStack->add('create_account', ENTRY_POST_CODE_ERROR);

}

Link to comment
Share on other sites

Try a couple more parens...

 

//* test for CM & Co postcode */
if ( ( substr($postcode,1,2) <> 'CM' ) and ( substr($postcode,1,2) <> 'CO' ) ) {
$error = true;
echo 'System available to residents of Essex postcodes CM & CO only!';

$messageStack->add('create_account', ENTRY_POST_CODE_ERROR);
}

 

ed

Link to comment
Share on other sites

Try a couple more parens...

 

//* test for CM & Co postcode */
if ( ( substr($postcode,1,2) <> 'CM' ) and ( substr($postcode,1,2) <> 'CO' ) ) {
$error = true;
echo 'System available to residents of Essex postcodes CM & CO only!';

$messageStack->add('create_account', ENTRY_POST_CODE_ERROR);
}

 

ed

 

I gave this a quick test and it is working. I will thoroughly test it tomorrow and work on a message box, as it is a little ugly.

Thanks for your help.

Link to comment
Share on other sites

Try this...might turn out to be more scalable:

	$district_array = array('CM', 'CO'); // define the districts

 if ( !in_array( substr($postcode,1,2), $district_array ) ){ // if not in the array
 echo 'System available to residents of Essex postcodes CM & CO only!'; // send string to screen
 $messageStack->add('create_account', ENTRY_POST_CODE_ERROR); // add to messageStack	
} # end if not in array

Bobby

Link to comment
Share on other sites

  • 4 weeks later...
Try this...might turn out to be more scalable:

	$district_array = array('CM', 'CO'); // define the districts

?if ( !in_array( substr($postcode,1,2), $district_array ) ){ // if not in the array
?echo 'System available to residents of Essex postcodes CM & CO only!'; // send string to screen
?$messageStack->add('create_account', ENTRY_POST_CODE_ERROR); // add to messageStack	
} # end if not in array

Bobby

 

 

This was working absolutely fine. Then the other day I started getting problems. I tested what was extracted from the postcode and found it was taking the 2nd and 3rd character. So I changed the substr 1,2 to substr 0,2. All Ok.

 

Site is now live and works for me. However, asked my brother to log on and have a go and he cannot create an account because of the postcode checker. Even though he lives in a supported area.

Changed back to substr 1,2 and he is now OK.

I could run both checks on the postcode but I would like to know why I am getting these probles. What is wrong with SUBSTR code?

Link to comment
Share on other sites

This was working absolutely fine. Then the other day I started getting problems. I tested what was extracted from the postcode and found it was taking the 2nd and 3rd character. So I changed the substr 1,2  to substr 0,2. All Ok.

 

Site is now live and works for me. However, asked my brother to log on and have a go and he cannot create an account because of the postcode checker. Even though he lives in a supported area.

Changed back to substr 1,2 and he is now OK.

I could run both checks on the postcode but I would like to know why I am getting these probles. What is wrong with SUBSTR code?

I am not talking about the scalable (array) version as I have only just seen that one.

Will give that a try Cheers.

Link to comment
Share on other sites

I am not talking about the scalable (array) version as I have only just seen that one.

Will give that a try Cheers.

 

 

Chemo.

Just seen and tried your array build for checking postcodes.

Itried it because of scalability and because the other way was causing errors.

Sometimes substr 1,2 would take the 1st and 2nd characters. Sometimes the 2nd and 3rd.

Changed substr to 0,2 and this worked well for a while and then started playing up and I had to change it back.

 

However, just tried your array and it didn't work. Again it is picking up the 2nd and 3rd characters.

I have put an echo of the substr at the top.

WWW.CLEANANDGROOM.CO.UK - create account

Any help would be appreciated.

I will update the original forum message.

Link to comment
Share on other sites

I am not talking about the scalable (array) version as I have only just seen that one.

Will give that a try Cheers.

Chemo.

Just seen and tried your array build for checking postcodes.

Itried it because of scalability and because the other way was causing errors.

Sometimes substr 1,2 would take the 1st and 2nd characters. Sometimes the 2nd and 3rd.

Changed substr to 0,2 and this worked well for a while and then started playing up and I had to change it back.

 

However, just tried your array and it didn't work. Again it is picking up the 2nd and 3rd characters.

I have put an echo of the substr at the top.

WWW.CLEANANDGROOM.CO.UK - create account

Any help would be appreciated.

I will update the original forum message.

 

Scrap that. Just checked PHP manual, it should be substr(0,2). We'll see how this works.

 

 

Link to comment
Share on other sites

I would worry about your images (or lack of them) before worrying about creating accounts, it seems none of your corner images are on the server, plus a few others.

Link to comment
Share on other sites

Why not go the easy route and enumerate the entry field on the form? Just use a drop down menu with the selections that you want available.

 

Bobby

Link to comment
Share on other sites

Hey guys...if the engine doesn't work or runs choppy what good is the paint job?

 

If customers cannot create an account properly to purchase do you think the graphics are going to matter?

 

Bobby

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...