Reputation: 61
I am designing a wordpress page on which i can add my own php code on as well.
I want to be able to add a form that users can enter their post code and based on their post code I wish to display a price.
So far I have come up with this, but need help in adding the IF statement to it:
<form action="" method="post">
Post Code: <input type="text" name="post_code" />
<input type="submit" />
</form>
Your Post Code is: <?php echo $_POST["post_code"]; ?>!<br />
And the price for that post is:
Can someone help me here please?
Appreciate your help in advance! :)
Upvotes: 0
Views: 411
Reputation:
rewritten based on commetns
<?php
//$_POST["post_code"]='SL1 2SA';
$post_price=array('SL1 2SA'=>'1.50', 'SL1 2GP'=>'2.99', 'SL2 3FA'=>'3.47');
$postage=$post_price[$_POST["post_code"]];
if(!empty($postage)){
echo 'Your Post Code is: '.$_POST["post_code"].'<br>And the price for that post is '. $postage; //1.5
}else{
echo 'bad post code';
}
?>
Upvotes: 2
Reputation: 624
$code = $_POST["post_code"];
if($code == '043132'){
$price = '15';
elseif($code == '632432'){
$price = '20';
}
If you need some elaborate structure, you need an mysql database, and you can organize this script in other way..
Upvotes: 1