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
https://forums.phpfreaks.com/topic/266176-i-am-a-php-retard/
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
https://forums.phpfreaks.com/topic/266176-i-am-a-php-retard/#findComment-1364038
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
https://forums.phpfreaks.com/topic/266176-i-am-a-php-retard/#findComment-1364040
Share on other sites

Archived

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

×
×
  • 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.