Jump to content

I am a PHP retard!


murray price

Recommended Posts

Hi,

 

I am trying to put together a script that allows visitors to my site to enter a postcode in a search box and then if the postcode matches one that is on a list the visitor is sent to a success page if not a fail page. This is the script I have so far:

 

<?php

 

$postcode_area = "kt18";

 

if(isset ($_POST["postcode_area"])){

if($_POST["postcode_area"] == $postcode_area){

 

    header("Location: ../area-covered.htm");

exit();

}

 

else{

  header("Location: ../area-not-covered.htm");

exit(); 

}

}

?>

 

This works fine if the user enters the one postcode shown 'KT18' but I have about 100 I want to include for the script.

 

Can anybody help me we out with this? I kinda know that I need to do a for each loop and explode it but I am just not advanced enough yet to pull this one off! Thanks for any help

Link to comment
Share on other sites

<?php

$valid = array('kt18','sm3','sw11','etc');

$lowercase_postal = strtolower($_POST['postal_code']);

if( in_array($lowercase_postal, $valid) ) {
echo 'Found';
} else {
echo 'Not found';
}

?>

Link to comment
Share on other sites

Hi, Thanks.

 

I have changed the echo's to header to redirect to a new page but when I add any search now it just directs to the fail page.

 

<?php

 

$valid = array('kt18','sm3','sw11','etc');

 

$lowercase_postal = strtolower($_POST['postal_code']);

 

if( in_array($lowercase_postal, $valid) ) {

header("Location: ../area-covered.htm");

exit();

 

} else {

header("Location: ../area-not-covered.htm");

exit();

}

 

?>

Link to comment
Share on other sites

Its ALIVE! Thanks for all your help...

 

<?php

 

$valid = array('kt18','sm3','sw11','etc');

 

$lowercase_postal = strtolower($_POST['postcode_area']);

 

if( in_array($lowercase_postal, $valid) ) {

header("Location: ../area-covered.htm");

exit();

} else {

header("Location: ../area-not-covered.htm");

exit();

}

 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.